Solved

data unable to store from js file to db2 database

Posted on 2011-03-24
1
659 Views
Last Modified: 2012-05-11
My input data from a jsp file is not stored in the database.

this is my
jsp file:



<%@page contentType="text/xml" %>
<%@page language="java" import="java.sql.*" %>
<jsp:useBean id="User" class="policeLibrary.User" />
<jsp:useBean id="c" class="policeLibrary.Complaints" />

<%
String XMLOutput = "<result>";
try
{
if(User. isUserLoggedIn()==false)
{      
      XMLOutput += "<error>please login to perform the Lodge a complaint </error>";
}
String compdate,dept,cname,incidentdate,psname,subject,descp,compsuspect,placeofoccurance;
int psid,pid,ctype;

compdate="12/11/2010";//request.getParameter("compdate");
dept="criminal";//request.getParameter("Dept");
cname="Missing";//request.getParameter("Cname");
incidentdate="12/11/2010";//request.getParameter("incidentdate");
psname="btm layout2nd stage";//request.getParameter("psname");
subject="hihello";//request.getParameter("compsubject");
descp="bye";//request.getParameter("compdescription");
compsuspect="nil";//request.getParameter("compsuspect");
placeofoccurance="bang";//request.getParameter("placeofocccurance");
String username;

//username=request.getParameter("username");
//int userid = User.getUid(username);
int userid=8;


psid=c.getPoliceStation(psname);
pid=c.getPolice(psid);
ctype=c.getComptype(cname);

if(userid==-1)
{
      XMLOutput += "<error>username is  not correct.please enter it </error>";
}

else
      {
      
      int b=      c.addComplaints(ctype  ,pid  ,psid  , userid  ,incidentdate  ,subject  ,descp ,compsuspect, placeofoccurance  ,"No");
      
      if(b!=-1)
            
            XMLOutput += "<success>the given admin is successfully added</success>";
      }

XMLOutput += "</result>";

}
catch(Exception e) {
      XMLOutput +="<error> Exception occured! </error>";
}
out.println(XMLOutput);
%>

this is the definition of addcomplaints mentioned above:

public int addComplaints(
int ctype  ,
int Pid  ,
int Psid  ,
int Userid  ,
String Incidentdate  ,
String Csubject  ,
 String Cdescription  ,
String Suspect ,
String Placeofoccurane  ,
String Iscomplaintclosed ) throws SQLException
            {
                  
                  User u = new User();
if(u.isUserIdExists(Userid) && u.isUserIdExists(Pid) && isSubjectproper(Csubject) && Cdescription.length()>0 )
                  {
      String query = "INSERT INTO complaint( ctype,Pid,Psid,Userid,Incidentdate,Csubject,Cdescription,Suspect,Placeofoccurance,Iscomplaintclosed)" +
                  " VALUES("+ctype+","+Pid+","+Psid+","+Userid+",'"+Incidentdate+"','"+Csubject+"','"+Cdescription+"','"+Suspect+"','"+Placeofoccurane+"','"+Iscomplaintclosed+"')";
                        int r=conn.runQuery(query);
                              //key = statement.getGeneratedKeys();
                              if(r==1)
                                    //return keygetInt(1);
                                    return 1;
                  }
                  return -1;
            }
            


this is the method that i use to connect the database:

public int runQuery(String query){
            int ans = -1;
            try
            {
                  curQuery = query;
                  curQueryStatement = c.prepareStatement(curQuery);
                  ans = curQueryStatement.executeUpdate();
            }
            catch(Exception e)
            {
                  System.out.println(e.getMessage());
            }
            return ans;
      }


i get the following error while executing
Method executeQuery cannot be used for update. ERRORCODE=-4476, SQLSTATE=null


i have assumed arbitrary input values in the Jsp file of which i am trying to add to my database complaint table.
wherin i get an error message only at the adding fuction.

pls help!


0
Comment
Question by:manikandan689
1 Comment
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 35208785
executeQuery cannot be used for update

when you do insert / update/ delete you should use executeNonQuery
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 555
RPG Free Prototypes using  *LDA data 5 167
DB2 error. 37 75
spring example non maven 4 82
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now