• Post Reply Bookmark Topic Watch Topic
  • New Topic

about servlets(very urgent)

 
jilla yuvaraj
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manoj Patel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[ edited out the wholesale quote Mike C.]

hi,
lookin at ur code i think u got a problem at
con=DriverManager.getConnection("jdbc dbc:test");
this shud be
con=DriverManager.getConnection("jdbcdbc:test");
and also write the connections in the init method of the servlet rather than the doGet() Method.
or keep the connection in a seperate class;
i ll send u the code if u want.
Do Cut and Paste
Make ur Life Easier
Bye;
[This message has been edited by Mike Curwen (edited December 03, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no doubt remaining that your situation is urgent, but starting multiple topics with the same question is not the best way of getting help.

Your previous posts:
http://www.javaranch.com/ubb/Forum7/HTML/006964.html http://www.javaranch.com/ubb/Forum7/HTML/006933.html


[This message has been edited by Mike Curwen (edited December 03, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the error is this:It makes me think you have a corrupted windows registry, or at very least, that your ADO installation has gone south.

Have you tried to re-install ADO? If you don't know what this is, the link is here: http://www.microsoft.com/data/download.htm

You are obtaining a jdbc-odbc connection, because you are getting these errors back. So the java code is probably not to blame.


[This message has been edited by Mike Curwen (edited December 03, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, to Manoj and others,

It is not *always* desirable to obtain a connection to a database at the earliest possible moment (ie, in a servlet init). What if the database has a limited connection pool? Or if there is no connection pooling available? Or what if the database access is infrequent?

In these cases, adopting a 'late-binding' strategy for shared resources is sometimes indicated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!