Connecting to database from servlets

greenspun.com : LUSENET : Java Programming : One Thread

Hi, I tried to connect to ms-access, oracle through servlets but i didn't get the proper result, instead i got the following exception

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Actually i created a user datasource name for a database , in which i have a table called emp which in turn has two fields eno and ename , both are of type text.

Here is my code import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class Sample extends HttpServlet{

public void doGet(HttpServletRequest req, HttpServletResponse res)throws

ServletException,IOException{ Connection con=null; Statement stmt=null; ResultSet rs=null; res.setContentType("text/html"); PrintWriter out = res.getWriter(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:test"); stmt=con.createStatement(); out.println("

welcome

"); } catch(Exception e){out.println(e);} } }

can anybody help me out?????

Yuvaraj

-- yuvaraj (yuva@lycos.com), November 28, 2001

Answers

Hi, con=DriverManager.getConnection ("jdbc:odbc:test","username","password"); u have to add a username and a password when u try to connect a database. u can set the username and password in settings of the "ODBC-datasources" ( I am not sure if its called like that - I only know the german expression) in the control panel on ur computer (if u are using windows) btw: u always have to close a resultset and after that u have to close the connection bye, Eric

-- Eric Velemans (eric.velemans@freenet.de), February 04, 2002.

shivani

-- shivani katageri (shivani_katageri@yahoo.com), March 04, 2005.

Moderation questions? read the FAQ