Forums Register Login

Help ! DriverManager.getConnection problem

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
any error messages ?
can you give us some example code ?
k
+Pie Number of slices to send: Send
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>");
}


}

}
+Pie Number of slices to send: Send
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
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 1978 times.
Similar Threads
JDBC Connectivity in Servlets
Oracle JDBC
How to connect to SQL Server 2000 ? please help !!!
JDBC connection to SQL Server 2000
Netbeans and MS Access
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:48:16.