wood burning stoves 2.0*
The moose likes JDBC and the fly likes Servlet JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Servlet JDBC" Watch "Servlet JDBC" New topic
Author

Servlet JDBC

Rohan Kalbhor
Ranch Hand

Joined: Aug 18, 2006
Posts: 78
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


..............................<br />Exceptions are a part of possibility<br />Errors are a part of truth<br />................................
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Rohan Kalbhor
Ranch Hand

Joined: Aug 18, 2006
Posts: 78
Hi above,
I have resolved the issue
Thankyou for your coordination
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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:
 
GeeCON Prague 2014
 
subject: Servlet JDBC