Solved

data unable to store from js file to db2 database

Posted on 2011-03-24
1
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 (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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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