• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help with JSP inserting into database

 
Sankar Bhamidi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Our development team has to insert about 42 rows into a database table. We have used beans and set and get properties using class ID = r. But we're facing an error "Operation must use an updateable query." Can someone figure out what's wrong and help us? Thank you! The code is below:
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<jsp:useBean id="r" class="Resume" scope="request"/>

<%String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";

Class.forName(driver);
Connection con=null;
try{
con=DriverManager.getConnection(url);

Statement stmt=con.createStatement();
String st= "insert into resume values("+r.getSsn()+",'"+r.getStreetAddress()+"','"+r.getCity()+"','"+r.getState()+"','"+r.getZip()+"','"+r.getCountry()+"','"+r.getEmail()+"',"+r.getPhone()+","+r.getFax()+",'"+r. getObjective()+"','"+r.getSchool1()+"','"+r.getGraduationYear1()+"','"+r.getMajor1()+"','"+r.getGpa1()+"','"+r.getSchool2()+"','"+r.getGraduationYear2()+"','"+r.getMajor2()+"','"+r .getGpa2()+"','"+r.getEmployerName1()+"','"+r.getJobTitle1()+"','"+r.getJobDescription1()+"','"+r.getFrom1()+"','"+r.getTo1()+"','"+r.getEmployerName2()+"','"+r.getJobTitle2()+"',' "+r.getJobDescription2()+"','"+r.getFrom2()+"','"+r.getTo2()+"','"+r.getEmployerName3()+"','"+r.getJobTitle3()+"','"+r.getJobDescription3()+"','"+r.getFrom3()+"','"+r.getTo3()+"',' "+r.getActivities()+"','"+r.getSkills()+"','"+r.getLanguages()+"','"+r.getAchievements()+"','"+r.getName1()+"','"+r.getTitle1()+"','"+r.getCompanyName1()+"','"+r.getAddress1()+"',' "+r.getPhone1()+"','"+r.getName2()+"','"+r.getTitle2()+"','"+r.getCompanyName2()+"','"+r.getAddress2()+"','"+r.getPhone2()+"','"+r.getName3()+"','"+r.getTitle3()+"','"+r.getCompany Name3()+"','"+r.getAddress3()+"','"+r.getPhone3()+"')";

stmt.executeUpdate(st);
stmt.close();
stmt=null;
}finally {

if(con!=null) {
con.close();
}
}
%>
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting the actual stacktrace gives a better clue to understand problem.

------------------
Sreenivasa Kumar Majji
Sun Certified Java Programmer
SCJP Mock Test
 
Bartholemu Smith
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Insead of using executeUpdate(), why dont you pass the SQL string to the preparedStatement "con.prepareStatement(sql);" and then just call the execute method...Try that. It might make a difference.

[This message has been edited by Faisal Dosani (edited November 05, 2001).]
 
rudayashanker
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sql query have to be in a single line.
The query have be same order of the database..attribute.
I have the same problem before..
I chage the structure now it works fine for me..
Thanks
Shankar.
------------------
 
Amol Khiste
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quoting MSDN KB article Q175168:

1. The most common reason is that the Internet Guest account (IUSR_MACHINE), which is by default part of the "Everyone" group, does not have Write permissions on the database file (.mdb). To fix this problem, use the Security tab in Explorer to adjust the properties for this file so that the Internet Guest account has the correct permissions. NOTE: When using Microsoft Access databases with ADO, it is also necessary to give the Internet Guest account Write permissions on the directory containing the .mdb file. This is because Jet creates an .ldb file to handle database locking. You may also need to give read/write permission on the "Temp" folder because Jet may create temporary files in this directory.
2. A second cause of this error is that the database was not opened with the correct MODE for writing. If you perform the Open on the Connection object, you use the Mode property to indicate the permissions on the connection as shown here:

NOTE: By default, the MODE is set to 0(adModeUnknown), which generally allows updates.
3. Another cause of this error is that the "Read Only" setting may be checked in the Options page for this DSN in the ODBC Manager.
4. The last issue and work around pertains to any SQL data source. The error can be caused by SQL statements that violate referential integrity of the database. Here are a few of the most common queries that fail:
- The simplest group to deal with are those you cannot change: crosstab, SQL pass-through, union, or update (or make-table) action queries that have UniqueValue properties set to Yes.
- Another very common cause is when the join includes linked ODBC tables that do not have unique indexes. In this case, there is no way for SQL to guarantee that records are unique in a table that has fields whose value will change with the query.
- One cause does have a robust workaround. If you try to update a join field on the "one" side of a "one-to-many" query it will fail unless you turn on cascading updates. This way, you delegate referential integrity to the JET engine."

[ February 06, 2003: Message edited by: Amol Khiste ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!