adnan_rais
asked on
General Database error
Hello..... I'm developing a sign up page for the new users in JSP. As I enter a new entry with a new loginid, it successfully gets added to the database, but when i try to check the result on entering the old id, it returns some kind of "General Error", means it does not move to "CreateUser.jsp?error=bad" for showing the error, "Username already exists". Plz do let me know the solution immediately.... I'e worked for hours on it but culdn't find the solution yet
// CreateUserAct.jsp
<%
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
Connection con = DriverManager.getConnectio n("jdbc:od bc:hello", "","");
ResultSet rs,rs1;
PreparedStatement ps = con.prepareStatement("sele ct * from customer where loginid = '" + request.getParameter("uid" ) + "'");
rs1 = ps.executeQuery() ;
String dbID = request.getParameter("uid" );
while(rs1.next())
{
if( dbID.equals(request.getPar ameter("ui d")) )
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password) values('" + request.getParameter("uid" ) + "','" + request.getParameter("pwd" ) + "')";
statement.executeUpdate(st rSQL);
statement.close();
%>
// CreateUser.jsp
String uid = request.getParameter("uid" );
if( uid != null ){
out.println("<input name=uid size=15 value=" + uid + ">");
}
// CreateUserAct.jsp
<%
Class.forName("sun.jdbc.od
Connection con = DriverManager.getConnectio
ResultSet rs,rs1;
PreparedStatement ps = con.prepareStatement("sele
rs1 = ps.executeQuery() ;
String dbID = request.getParameter("uid"
while(rs1.next())
{
if( dbID.equals(request.getPar
{
response.sendRedirect("Cre
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password)
statement.executeUpdate(st
statement.close();
%>
// CreateUser.jsp
String uid = request.getParameter("uid"
if( uid != null ){
out.println("<input name=uid size=15 value=" + uid + ">");
}
ASKER
The JBuilder returns the error as
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
javax.servlet.ServletExcep tion: General error
at org.apache.jasper.runtime. PageContex tImpl.hand lePageExce ption(Page ContextImp l.java:463 )
at org.apache.jsp.CreateUserA ct$jsp._js pService(C reateUserA ct$jsp.jav a:136)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.jasper.servlet. JspServlet $JspServle tWrapper.s ervice(Jsp Servlet.ja va:202)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:382)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:474)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 93)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:243)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:190)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2343)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:170)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:170 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.connec tor.http.H ttpProcess or.process (HttpProce ssor.java: 1012)
at org.apache.catalina.connec tor.http.H ttpProcess or.run(Htt pProcessor .java:1107 )
at java.lang.Thread.run(Threa d.java:484 )
root cause
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6060)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQL ExecDirect (JdbcOdbc. java:2494)
at sun.jdbc.odbc.JdbcOdbcStat ement.exec ute(JdbcOd bcStatemen t.java:334 )
at sun.jdbc.odbc.JdbcOdbcStat ement.exec uteUpdate( JdbcOdbcSt atement.ja va:284)
at org.apache.jsp.CreateUserA ct$jsp._js pService(C reateUserA ct$jsp.jav a:124)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.jasper.servlet. JspServlet $JspServle tWrapper.s ervice(Jsp Servlet.ja va:202)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:382)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:474)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 93)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:243)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:190)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2343)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:170)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:170 )
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 64)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline.invo keNext(Sta ndardPipel ine.java:5 66)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:472)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 43)
at org.apache.catalina.connec tor.http.H ttpProcess or.process (HttpProce ssor.java: 1012)
at org.apache.catalina.connec tor.http.H ttpProcess or.run(Htt pProcessor .java:1107 )
at java.lang.Thread.run(Threa d.java:484 )
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
javax.servlet.ServletExcep
at org.apache.jasper.runtime.
at org.apache.jsp.CreateUserA
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.connec
at org.apache.catalina.connec
at java.lang.Thread.run(Threa
root cause
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcStat
at sun.jdbc.odbc.JdbcOdbcStat
at org.apache.jsp.CreateUserA
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.connec
at org.apache.catalina.connec
at java.lang.Thread.run(Threa
Please post the error-message you receive in details
ok! You posted while I asked for it ;-)
ASKER
u've been a gr8 help to me JNic.... plz do let me know it's correct solution immediately
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx JNic ur code worked but just 1 more simple question to ask......
Suppose the page url is
http://localhost/CreateUser.jsp?error=bad&addr=uhjggfytfdtdresdresres+jknjjhgjghfftrdfd
As Itry to retrieve the value of variable 'addr' from the url using request.getParameter(), it returns the characters before the first spcace, i.e. , uhjggfytfdtdresdresres in the 'address' textfield. Why is it so? I need the complete data to be displayed in the text field. Just 1 more answer plzz.....
Suppose the page url is
http://localhost/CreateUser.jsp?error=bad&addr=uhjggfytfdtdresdresres+jknjjhgjghfftrdfd
As Itry to retrieve the value of variable 'addr' from the url using request.getParameter(), it returns the characters before the first spcace, i.e. , uhjggfytfdtdresdresres in the 'address' textfield. Why is it so? I need the complete data to be displayed in the text field. Just 1 more answer plzz.....
Hmmmm, cant see any error in that url.
String address = request.getParameter("addr "); should work.
Try posting your code.
String address = request.getParameter("addr
Try posting your code.
BTW, you should finish this question:
https://www.experts-exchange.com/questions/20785486/Extracting-the-last-value-stored-in-a-particular-field.html
;-)
https://www.experts-exchange.com/questions/20785486/Extracting-the-last-value-stored-in-a-particular-field.html
;-)
ASKER
Hi JNic.... the matter isn't solved yet... according to the following program, the page must check either the userID and account_no given by the user does exist in the database( or not ).
1 - If I enter new userID and new Account_no, the record safely gets inserted in both the tables(i.e., 'customer' and 'account')
2 - If I enter an old userID and a new account_no, the page returns an error saying .... "Username already exists"
3 - If I enter a new userID and an old Account_no, the
page returns an error saying .... "Account # already exists" but alongwith it inserts the record in 'customer' table
No. 3 points to the major problem.... the record must not be inserted in the 'customer' table even if the user gives a new ID. I hope u understand what I mean to say..... What should be the change in the following code.... Plz do reply back immediately as I'll b obliged to u
<%
try{
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
Connection con = DriverManager.getConnectio n("jdbc:od bc:hello", "","");
PreparedStatement ps = con.prepareStatement("sele ct * from customer where loginid = '" + request.getParameter("uid" ) + "'");
ResultSet rs = ps.executeQuery();
String dbID = request.getParameter("uid" );
int i;
String ac_no = request.getParameter("acc_ no");
String ac1;
while(rs.next())
{
if(dbID.equals(request.get Parameter( "uid")))
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
}
}
PreparedStatement ps4 = con.prepareStatement("sele ct * from account where account_no = " + request.getParameter("acc_ no") + "");
ResultSet rs4 = ps4.executeQuery();
while(rs4.next())
{
int i = rs4.getInt("account_no");
String ac1 = new Integer(i).toString();
if(ac1.equals(request.getP arameter(" acc_no")))
{
response.sendRedirect("Cre ateUser.js p?ac=bad&a cc_no=" + request.getParameter("acc_ no") + "&uid=" + request.getParameter("uid" ) + "");
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password) values('" + request.getParameter("uid" ) + "','" + request.getParameter("pwd" ) + "')";
statement.executeUpdate(st rSQL);
statement.close();
Statement statement2 = con.createStatement();
String strSQL2 = "insert into account(account_no,loginid ) values(" + request.getParameter("acc_ no") + ",'" + request.getParameter("uid" ) + "')";
statement2.executeUpdate(s trSQL2);
statement2.close();
}
catch(SQLException e){
e.printStackTrace();
}
%>
1 - If I enter new userID and new Account_no, the record safely gets inserted in both the tables(i.e., 'customer' and 'account')
2 - If I enter an old userID and a new account_no, the page returns an error saying .... "Username already exists"
3 - If I enter a new userID and an old Account_no, the
page returns an error saying .... "Account # already exists" but alongwith it inserts the record in 'customer' table
No. 3 points to the major problem.... the record must not be inserted in the 'customer' table even if the user gives a new ID. I hope u understand what I mean to say..... What should be the change in the following code.... Plz do reply back immediately as I'll b obliged to u
<%
try{
Class.forName("sun.jdbc.od
Connection con = DriverManager.getConnectio
PreparedStatement ps = con.prepareStatement("sele
ResultSet rs = ps.executeQuery();
String dbID = request.getParameter("uid"
int i;
String ac_no = request.getParameter("acc_
String ac1;
while(rs.next())
{
if(dbID.equals(request.get
{
response.sendRedirect("Cre
}
}
PreparedStatement ps4 = con.prepareStatement("sele
ResultSet rs4 = ps4.executeQuery();
while(rs4.next())
{
int i = rs4.getInt("account_no");
String ac1 = new Integer(i).toString();
if(ac1.equals(request.getP
{
response.sendRedirect("Cre
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password)
statement.executeUpdate(st
statement.close();
Statement statement2 = con.createStatement();
String strSQL2 = "insert into account(account_no,loginid
statement2.executeUpdate(s
statement2.close();
}
catch(SQLException e){
e.printStackTrace();
}
%>
ASKER
i know it's too much to ask for just 20 points but belive me it's the need
Hi, you wrote:
String dbID = request.getParameter("uid" );
int i;
String ac_no = request.getParameter("acc_ no");
String ac1;
while(rs.next())
{
if(dbID.equals(request.get Parameter( "uid")))
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
}
}
Note that: if(dbID.equals(request.get Parameter( "uid"))) always will return TRUE!
Maybe you meant: if(rs.getString("uid").equ als(dbID)) ??
About problem 3:
I think I will need more of your code to answer this. Where do the error-messages come from? (ie "username allready exists" aso). I dont see them in your code...
Let me see some more.... ;-)
String dbID = request.getParameter("uid"
int i;
String ac_no = request.getParameter("acc_
String ac1;
while(rs.next())
{
if(dbID.equals(request.get
{
response.sendRedirect("Cre
}
}
Note that: if(dbID.equals(request.get
Maybe you meant: if(rs.getString("uid").equ
About problem 3:
I think I will need more of your code to answer this. Where do the error-messages come from? (ie "username allready exists" aso). I dont see them in your code...
Let me see some more.... ;-)
ASKER
They come from CreateUser.jsp . The code is as follows:
<%
String err = request.getParameter("erro r");
String err1 = request.getParameter("ac") ;
if( err != null )
{
out.println("<tr><td align=middle colspan=2><b><font color=red size=3>Username already exists</font></b></td></tr >");
}else if( err1 != null )
{
out.println("<tr><td align=middle colspan=2><b><font color=red size=3>Account # already exists for some other user</font></b></td></tr>" );
}
%>
<%
String err = request.getParameter("erro
String err1 = request.getParameter("ac")
if( err != null )
{
out.println("<tr><td align=middle colspan=2><b><font color=red size=3>Username already exists</font></b></td></tr
}else if( err1 != null )
{
out.println("<tr><td align=middle colspan=2><b><font color=red size=3>Account # already exists for some other user</font></b></td></tr>"
}
%>
I am not sure about this, but try to put a return statement after your redirects. - Maybe the rest of the jsp is exectuted before the redirect works. A return should stop the jsp-exectution immediately.
Fx:
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
return;
}
Do it both places where you have response.sendRedirect, and let me know if it helps.
Fx:
{
response.sendRedirect("Cre
return;
}
Do it both places where you have response.sendRedirect, and let me know if it helps.
ASKER
no it didn't
OK - I changed some parts of your code. Try it.
<%
try{
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
Connection con = DriverManager.getConnectio n("jdbc:od bc:hello", "","");
PreparedStatement ps = con.prepareStatement("sele ct * from customer where loginid = '" + request.getParameter("uid" ) + "'");
ResultSet rs = ps.executeQuery();
String dbID = request.getParameter("uid" );
int i;
String ac_no = request.getParameter("acc_ no");
String ac1;
while(rs.next())
{
if(rs.getString("loginid") .equals(db ID))) //CHANGED
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
return; //CHANGED
}
}
PreparedStatement ps4 = con.prepareStatement("sele ct * from account where account_no = '" + request.getParameter("acc_ no") + "'"); // CHANGED - single quation-marks added around request.getParameter("acc_ no")
ResultSet rs4 = ps4.executeQuery();
while(rs4.next())
{
int i = rs4.getInt("account_no");
String ac1 = new Integer(i).toString();
if(ac1.equals(request.getP arameter(" acc_no")))
{
response.sendRedirect("Cre ateUser.js p?ac=bad&a cc_no=" + request.getParameter("acc_ no") + "&uid=" +request.getParameter("uid ") + "");
return; // CHANGED
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password) values('" + request.getParameter("uid" ) + "','" + request.getParameter("pwd" ) + "')";
statement.executeUpdate(st rSQL);
statement.close();
Statement statement2 = con.createStatement();
String strSQL2 = "insert into account(account_no,loginid ) values(" + request.getParameter("acc_ no") + ",'" + request.getParameter("uid" ) + "')";
statement2.executeUpdate(s trSQL2);
statement2.close();
}
catch(SQLException e){
e.printStackTrace();
}
%>
<%
try{
Class.forName("sun.jdbc.od
Connection con = DriverManager.getConnectio
PreparedStatement ps = con.prepareStatement("sele
ResultSet rs = ps.executeQuery();
String dbID = request.getParameter("uid"
int i;
String ac_no = request.getParameter("acc_
String ac1;
while(rs.next())
{
if(rs.getString("loginid")
{
response.sendRedirect("Cre
return; //CHANGED
}
}
PreparedStatement ps4 = con.prepareStatement("sele
ResultSet rs4 = ps4.executeQuery();
while(rs4.next())
{
int i = rs4.getInt("account_no");
String ac1 = new Integer(i).toString();
if(ac1.equals(request.getP
{
response.sendRedirect("Cre
return; // CHANGED
}
}
Statement statement = con.createStatement();
String strSQL = "insert into customer(loginid,password)
statement.executeUpdate(st
statement.close();
Statement statement2 = con.createStatement();
String strSQL2 = "insert into account(account_no,loginid
statement2.executeUpdate(s
statement2.close();
}
catch(SQLException e){
e.printStackTrace();
}
%>
The problem is that you are not checking your login id with the database ids.
The code that u have written:-
String dbID = request.getParameter("uid" );
while(rs1.next())
{
//this statement will always be true. here u should check like this.
if( dbID.equals(rs1.getString( "uid") )
Then it will give u proper result.
if( dbID.equals(request.getPar ameter("ui d")) )
{
response.sendRedirect("Cre ateUser.js p?error=ba d&uid=" + request.getParameter("uid" ) + "");
}
}
The code that u have written:-
String dbID = request.getParameter("uid"
while(rs1.next())
{
//this statement will always be true. here u should check like this.
if( dbID.equals(rs1.getString(
Then it will give u proper result.
if( dbID.equals(request.getPar
{
response.sendRedirect("Cre
}
}
ASKER