• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

about servlets (very urgent)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:odbc: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
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jilla,
maybe your
getConnection(String url);
does not work with servlets. I use getConnection(String url, String user, String password).
But that might be wrong. Don't have the time to check the code more thorougly.
In every case inform yourself about servlet lifecycle. Usually one would handle initialization/destruction of things like a database connection in the init()/destroy() methods. Cause so the db-Connection is only created once.
http://java.sun.com/docs/books/tutorial/servlets/lifecycle/init.html
regards axel
 
What are you doing in my house? Get 'em tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic