This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Connecting to database form servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connecting to database form servlets" Watch "Connecting to database form servlets" New topic
Author

Connecting to database form servlets

jilla yuvaraj
Greenhorn

Joined: Nov 28, 2001
Posts: 4
i tried to connect to databases ms-access through servlets but i didn't get the correct answer, when i used the same program as application it was working properly,
i have a database in which i have a table called emp which has two fieds one is eno and another one is ename , both are of type text.
The actual code is
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 dbc:test");
stmt=con.createStatement();
rs=stmt.executeQuery("select * from emp");
out.println("<html>welcome<html><ul>");
while(rs.next())
{
out.println("<li>"+rs.getString("eno")+" "+rs.getString("ename"));
}
out.println("</ul>");
} catch(Exception e){out.println(e);}

}
}
i got the following exception when i create the dsn as system dsn
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'DriverId'.
i got the following exception when i create the dsn as user dsn

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

i tried the same with username and password for oracle
but i got the same exception as i got for ms-access.
can anybody help me out ?? do i need to do any modification in creating the dsn name??

Yuvaraj

Bashir Mirzad
Greenhorn

Joined: Nov 28, 2001
Posts: 25
Hi dear !
for your Oracle problem I can tell if you have problem wiht the user name and password, if you using Windows 2000, go to the Control Panel/Performance and Maintenance/Administrative Tools/Services then start the all services for Oracle
Hope it can help
Bashir
Pranit Saha
Ranch Hand

Joined: Sep 09, 2001
Posts: 130

i got the following exception when i create the dsn as user dsn

You have o make the DSN as System DSN..
Pranit..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to database form servlets