Win a copy of Learning Regular Expressions this week in the General Computing forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Help ! DriverManager.getConnection problem  RSS feed

 
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.
 
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>");
}


}

}
 
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
Boost this thread!