Solved

General Database error

Posted on 2003-11-08
17
346 Views
Last Modified: 2010-04-01
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.odbc.JdbcOdbcDriver");

  Connection con = DriverManager.getConnection("jdbc:odbc:hello","","");

  ResultSet rs,rs1;
  PreparedStatement ps = con.prepareStatement("select * from customer where loginid = '" + request.getParameter("uid") + "'");
  rs1 = ps.executeQuery() ;

  String dbID = request.getParameter("uid");
  while(rs1.next())
  {
    if( dbID.equals(request.getParameter("uid")) )
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
    }
  }

  Statement statement = con.createStatement();
  String strSQL = "insert into customer(loginid,password) values('" + request.getParameter("uid") + "','" + request.getParameter("pwd") + "')";
  statement.executeUpdate(strSQL);
  statement.close();
%>

// CreateUser.jsp

  String uid = request.getParameter("uid");
  if( uid != null ){
      out.println("<input name=uid size=15 value=" + uid + ">");
  }
0
Comment
Question by:adnan_rais
  • 8
  • 8
17 Comments
 

Author Comment

by:adnan_rais
ID: 9706946
bobbit31, kotan if u do know the solution plz help me out then
0
 

Author Comment

by:adnan_rais
ID: 9706969
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.ServletException: General error
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:463)
      at org.apache.jsp.CreateUserAct$jsp._jspService(CreateUserAct$jsp.java:136)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      at java.lang.Thread.run(Thread.java:484)


root cause

java.sql.SQLException: General error
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6060)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
      at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:334)
      at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:284)
      at org.apache.jsp.CreateUserAct$jsp._jspService(CreateUserAct$jsp.java:124)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
      at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
      at java.lang.Thread.run(Thread.java:484)

0
 
LVL 1

Expert Comment

by:JNic
ID: 9706981
Please post the error-message you receive in details
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Expert Comment

by:JNic
ID: 9706984
ok! You posted while I asked for it ;-)
0
 

Author Comment

by:adnan_rais
ID: 9706993
u've been a gr8 help to me JNic.... plz do let me know it's correct solution immediately
0
 
LVL 1

Accepted Solution

by:
JNic earned 20 total points
ID: 9707012
I am not perfectly sure, but I think it is because the jsp doesn't know how to handle the SQLException.

Try to embed your code in a TRY-block, and do a SQLException-catch after. Like this:

// CreateUserAct.jsp

<%
try{
 
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

  Connection con = DriverManager.getConnection("jdbc:odbc:hello","","");

  ResultSet rs,rs1;
  PreparedStatement ps = con.prepareStatement("select * from customer where loginid = '" + request.getParameter("uid") + "'");
  rs1 = ps.executeQuery() ;

  String dbID = request.getParameter("uid");
  while(rs1.next())
  {
    if( dbID.equals(request.getParameter("uid")) )
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
    }
  }

  Statement statement = con.createStatement();
  String strSQL = "insert into customer(loginid,password) values('" + request.getParameter("uid") + "','" + request.getParameter("pwd") + "')";
  statement.executeUpdate(strSQL);
  statement.close();
%>

// CreateUser.jsp

  String uid = request.getParameter("uid");
  if( uid != null ){
      out.println("<input name=uid size=15 value=" + uid + ">");
  }
}
catch(SQLException e){e.printStackTrace();}


This is a problem when you write jsps instead of java-classes; in regular java I am sure your editor would have objected because you did not handle the SQLException.
0
 

Author Comment

by:adnan_rais
ID: 9707075
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.....
0
 
LVL 1

Expert Comment

by:JNic
ID: 9707305
Hmmmm, cant see any error in that url.
String address = request.getParameter("addr"); should work.
Try posting your code.
0
 
LVL 1

Expert Comment

by:JNic
ID: 9709727
0
 

Author Comment

by:adnan_rais
ID: 9710161
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.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:hello","","");

  PreparedStatement ps = con.prepareStatement("select * 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.getParameter("uid")))
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
    }
  }

  PreparedStatement ps4 = con.prepareStatement("select * 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.getParameter("acc_no")))
    {
      response.sendRedirect("CreateUser.jsp?ac=bad&acc_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(strSQL);
  statement.close();

  Statement statement2 = con.createStatement();
  String strSQL2 = "insert into account(account_no,loginid) values(" + request.getParameter("acc_no") + ",'" + request.getParameter("uid") + "')";
  statement2.executeUpdate(strSQL2);
  statement2.close();
}
catch(SQLException e){
  e.printStackTrace();
}
%>
0
 

Author Comment

by:adnan_rais
ID: 9710233
i know it's too much to ask for just 20 points but belive me it's the need
0
 
LVL 1

Expert Comment

by:JNic
ID: 9710624
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.getParameter("uid")))
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
    }
  }

Note that: if(dbID.equals(request.getParameter("uid")))  always will return TRUE!

Maybe you meant: if(rs.getString("uid").equals(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.... ;-)
0
 

Author Comment

by:adnan_rais
ID: 9710801
They come from CreateUser.jsp . The code is as follows:

<%
  String err = request.getParameter("error");
  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>");
  }
%>
0
 
LVL 1

Expert Comment

by:JNic
ID: 9710837
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("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
   return;
}

Do it both places where you have response.sendRedirect, and let me know if it helps.
0
 

Author Comment

by:adnan_rais
ID: 9710910
no it didn't
0
 
LVL 1

Expert Comment

by:JNic
ID: 9710962
OK -  I changed some parts of your code. Try it.


<%
try{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con = DriverManager.getConnection("jdbc:odbc:hello","","");

  PreparedStatement ps = con.prepareStatement("select * 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(dbID)))  //CHANGED
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
      return;  //CHANGED
    }
  }

  PreparedStatement ps4 = con.prepareStatement("select * 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.getParameter("acc_no")))
    {
      response.sendRedirect("CreateUser.jsp?ac=bad&acc_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(strSQL);
  statement.close();

  Statement statement2 = con.createStatement();
  String strSQL2 = "insert into account(account_no,loginid) values(" + request.getParameter("acc_no") + ",'" + request.getParameter("uid") + "')";
  statement2.executeUpdate(strSQL2);
  statement2.close();
}
catch(SQLException e){
  e.printStackTrace();
}
%>
0
 

Expert Comment

by:paragagarwal
ID: 9712360
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.getParameter("uid")) )
    {
      response.sendRedirect("CreateUser.jsp?error=bad&uid=" + request.getParameter("uid") + "");
    }
  }

 
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
report generation frameworks 1 64
spring AOP 6 85
Handle form fields in spring mvc controller 1 64
spring JDBC Template example error 26 240
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question