I am trying to connect to database by using
servlets... The code that i am trying is as follows
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TestJdb extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Connection conn;
Statement stmt;
String url = "jdbc dbc:lak";
String sql = "select * from course";
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head></head><body><b>database</b>");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
out.println("registered the driver");
}
catch(java.lang.ClassNotFoundException e)
{
out.println("Class not found exception:");
out.println(e.getMessage());
}
catch(Exception e)
{
out.println("exception:");
out.println(e.getMessage());
}
try{
conn = DriverManager.getConnection(url,"system","manager");
out.println("<b>connection succeeded");
}
catch(SQLException e)
{
out.println("SQL Excpetion occured in connection");
}
out.println("</body></html>");
}
}
I am getting SQLException.... Actually I have tried the same logic by using application, it was working, but with servlets it is givin SQLException.... I have tried somany ways... I could not resolve it.... Can somebody tell me what's wrong in the code...
Thanks
Lakshmi