File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet JDBC

 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have 1 servlet and 1 java program...when i try to invoke java program from servlet it gives "invalids cursor state"

servlet code
----------
package coreservlets;
import dblogic.*;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.TimeZone.*;

public class tryout extends HttpServlet
{
dblogic db;
String disp;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String user = request.getParameter("uid");
String pass = request.getParameter("pass");
String submit = request.getParameter("depp");
try{
dblogic db2=new dblogic();
int ret=db2.db_auth(user,pass);
if(ret==0)
{
disp="Password Accepted";
}
else
{
disp="Password not Accepted";
}
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
String title = "Time Sheet Authentification";
out.println
(docType +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"Status=="+ disp +
"</BODY></HTML>");

}catch(Exception e)
{
out.println(e);
}
}
};
----------------

java code
------------
package dblogic;
import java.sql.*;
import java.io.*;

public class dblogic
{
Connection con;
Statement stmt;
int j;
public dblogic()throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String myDB =
"jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=E://Tomcat 6.0/webapps/ROOT/database/db_timesheet.MDB";
con = DriverManager.getConnection(myDB,"","");
System.out.println("Done");

}
public int dblogic(String s1,String s2,String s3)throws Exception
{

PreparedStatement ps;
String strn="INSERT INTO tabstat values('"+s1+"','"+s2+"','"+s3+"');";
ps=con.prepareStatement(strn);
int row_affe=ps.executeUpdate();
//System.out.println(row_affe);
System.out.println(strn);
con.close();
return row_affe;

}

public int db_auth(String id,String pass)
{

try{

ResultSet rs1;

Statement st1=con.createStatement();
rs1=st1.executeQuery("select pwd from auth_tab where id='"+id+"';");
{
rs1.next();
}
String m5=(rs1.getString(1));
System.out.println(m5);
if(m5.equals(pass))
{
j=0;

//("password accepted...!!!");
}
else
{
j=1;

//("sorry..wrong pasword...try again");
}

con.close();
}catch(Exception ae)

{
System.out.println("Problem in Database"+ae);

}

return j;

//
}
-------------------
please help
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rohan Kalbhor:

rs1=st1.executeQuery("select pwd from auth_tab where id='"+id+"';");
{ // line 1
rs1.next();
}// line 2
String m5=(rs1.getString(1));
System.out.println(m5);


hi above,

can you tell me why you have braces { before and after rs1.next() } ?

Tip: .next() method is return boolean, return true when resultset have records otherwise false. or check Java Doc

hope it helps.
 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi above,
I have resolved the issue
Thankyou for your coordination
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rohan Kalbhor:
I have resolved the issue
Thankyou for your coordination


Hi Rohan,
Its glads to see that you have resolve the issue,
:thumb:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic