Solved

data unable to store from js file to db2 database

Posted on 2011-03-24
1
657 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bean mapper frameworks 5 56
Catalog Index 9 114
Use tracing facilities in your browser steps 2 91
SQL400 max size 5 57
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…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

22 Experts available now in Live!

Get 1:1 Help Now