Solved

data unable to store from js file to db2 database

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project jars 7 55
Monitor SQL Insert 8 74
how to add new optional parameter to JSP 1 49
difference between sorce folder and folder in eclipise 3 29
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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