wood burning stoves 2.0*
The moose likes Servlets and the fly likes Help ! DriverManager.getConnection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Help ! DriverManager.getConnection problem

raj guntupalli
Greenhorn

Joined: Dec 16, 2002
Posts: 27
When I to connect to a access databse with a jdbc-odbc bridge it connects fine and everything works out.But when I try to connect the same database from the servlet in my tomacat4.0 DriverManager.getConnection("jdbc dbc D","",""); is not working.Can anyone please help me.bye.
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
any error messages ?
can you give us some example code ?
k
raj guntupalli
Greenhorn

Joined: Dec 16, 2002
Posts: 27
I commented some of the code to check the connectivity with the database (instead of initializing from the descriptor file).
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet
{
Connection dbConnection;
/*public void init()
{

//ServletConfig config=getServletConfig();
//System.out.println(getServletName()+":Initializing...");
//String driverClassName=config.getInitParameter("driverclassname");
//String dbURL=config.getInitParameter("dburl");
//String username=config.getInitParameter("username");
//String password=config.getInitParameter("password");
/*try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){System.out.print("beep");}
/* try
{
dbConnection=DriverManager.getConnection("jdbc dbc b1","hello","welcome");
}catch(SQLException e){}
System.out.println("Initialized");*/
//}
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{

PrintWriter pw=res.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbConnection=DriverManager.getConnection("jdbc dbc D","","");
Statement smt=dbConnection.createStatement();
ResultSet r=smt.executeQuery("SELECT * FROM MySQLODBC");
pw.println("<html>");
pw.println("<body>");
pw.println("<h1>hello</h1>");
while(r.next())
{
int j=r.getInt("ID");
String s = r.getString("name");
int i = r.getInt("age");
pw.println("ROW = "+j+" " + s + " " + i);
}
pw.println("</body>");
pw.println("</html>");
smt.close();
dbConnection.close();
}
catch(Exception e)
{
pw.println("<html>");
pw.println("<h1>"+e+"no result</h1>");
pw.println("</html>");
}


}

}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The same question has also been posted HERE in the JDBC forum and we are experiencing duplicate conversations.
Since the JDBC is the better forum for this question, I'm going to close this thread and direct anyone who wants to help to go to the other thread.
Please don't post the same question in multiple forums.
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help ! DriverManager.getConnection problem