Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic

Help ! DriverManager.getConnection problem

 
raj guntupalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 388
  • Mark post as helpful
  • send pies
  • Report post to moderator
any error messages ?
can you give us some example code ?
k
 
raj guntupalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic