Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

SERVLET JDBC

  Asked By: Fern    Date: Jul 09    Category: Java    Views: 753
  

I have a problem with my servlet file. I could not
update my oracle database when I fill the forms in the
HTML file. there is no problem to compile this
servlet, but the database always cannot be updated. I
could not figure out what's the problem. couls sb let
me know what's wrong with this? attached are the java
servlet and html files?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Alvin Nguyen     Answered On: Jul 09

For inserting to DB you can’t use stmt.executeQuery method, you must use stmt.executeUpdate( sqlStatment ).Meanwhile you must commit any changes in Oracle ,you can do it with stmt.executeUpdate( “commit” ) or you can set auto commit to true. You can do it with this instruction conn.setAutoCommit(true).please check its syntax.



I hope this can help you, let me know if you have any problem.

 
Answer #2    Answered By: Jackson Bouchard     Answered On: Jul 09

thank you very much for your help. I did it by your
instruction. there is an Incompatible types error with
this phrase:


rset=stmt.executeUpdate("insert into kairegistration
values ('"+studentid+"','"+coursenumber+"')");

I do not know how should i make modification to this
phrase. and please refer to attached
Studentaddcourse1.java file.

 
Answer #3    Answered By: Isaac Williams     Answered On: Jul 09

I have slightly modified your code example (see the attachment) ->
ie. the update/insert returns an INT, not a ResultSet.
The error you are reffering to (incompatible types) could be related
to how your 'kairegistration' table fields look like. In your INSERT
statement all data are inserted as String. If the DB field type is a
NUMBER (for example), you have to add your argument as a number as
well (therefore without the quotation marks around).
So check out the definition of your DB table and try the modified
example again.

the modified code lines:


1. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
2. try {
StringBuffer sql = new StringBuffer();
String sqlString = "";
sql.append("insert into kairegistration values ('");
sql.append(studentid);
sql.append("','");
sql.append(coursenumber);
sql.append("')");
sqlString = sql.toString();

int resultDB = stmt.executeUpdate(sqlString);
}

 
Didn't find what you were looking for? Find more on SERVLET JDBC Or get search suggestion and latest updates.




Tagged: