Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 679
  • Last Modified:

data unable to store from js file to db2 database

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
manikandan689
Asked:
manikandan689
1 Solution
 
momi_sabagCommented:
executeQuery cannot be used for update

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now