I am doing a servlet program that connects to a MSACCESS database,retrieves data and redirects the user to another page. I find the following error
java.sql.SQLException: General error
Login.java accesses esql.java which retrieves data from MSACCESS server.
PLease help!!!
My Servlet code: Login.java
import java.io.*;
import java.sql.*;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Login extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
String str1="";
String cat="";
String s1=request.getParameter("name");
String s2=request.getParameter("passwd");
PrintWriter out=response.getWriter();
response.setContentType("text/html");
System.out.println(s1);
System.out.println(s2);
esql e = new esql();
int x = e.method(s1,s2);
System.out.println(x);
if(x == 1)
{
response.sendRedirect("arakonnam.html");
}
}
}
esql.java
import java.io.*;
import java.sql.*;
public class esql
{
int method(String name, String pass)
{
try
{
String str = "SELECT * FROM voterlogin where voterID=? and password=?";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("Jdbc:Odbc:db1","","");
Statement S = c.createStatement();
PreparedStatement smt = c.prepareStatement(str);
smt.setString(1,name);
smt.setString(2,pass);
ResultSet r = smt.executeQuery();
if(r == null)
return 0;
else
return 1;
}
catch(Exception e)
{
System.out.println(e);
}
return 0;
}
String fetchConstituency(String name)
{
try
{
String str = "SELECT * FROM voterinfo where voterID=?";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("Jdbc:Odbc:db1","","");
Statement S = c.createStatement();
PreparedStatement smt = c.prepareStatement(str);
smt.setString(1,name);
ResultSet r = smt.executeQuery();
String qs="";
r.next();
qs = r.getString("constituency");
System.out.println(qs);
return qs;
}
catch(Exception e)
{
System.out.println(e);
}
return null;
}
public static void main(String args[])
{
esql e = new esql();
e.fetchConstituency("1");
}
}