Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This is driving me crazy

 
xue shen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean that connect to my access database, and an jsp file that uses that bean.
if I uses the code on the jsp file without the bean, it would connect to the database and update the database without problem.
If I use the bean, with the same code, it will give me any error say:
"javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] The INSERT INTO statement contains the following unknown field name: ''username''. Make sure you have typed the name correctly, and try the operation again.
"
The operation is try to update a user database after the user registration is successfull.

here is the codes:
the code which works in jsp:
User newuser = new User("dave", "test", "dave@yahoo.com");
PreparedStatement addRecord;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:user","","");
addRecord = con.prepareStatement("INSERT INTO User (username, password, email)VALUES( ?, ?, ? )");
//stat.executeUpdate("INSERT INTO ForumUser (username, password, email)VALUES('dave', 'test', 'dave@yahoo.com')");
addRecord.setString( 1, newuser.getUsername() );
addRecord.setString( 2, newuser.getPassword() );
addRecord.setString( 3, newuser.getEmail() );
addRecord.executeUpdate();
The above code would insert the user into the database with no problem.
but gives me trouble if it is in a bean. Any insight would be appreciated.
 
Khurram Shahood(SCJP2)
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
just check the field name plz
 
xue shen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the field name many times. I am completely baffled by this problem. Any insight from any body?
 
Ming Chen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Separate your DB connection pool from Bean.
Call a DB connection pool from jsp page, then set pool to your Bean, run you bean. it should be working, and it's also easy for debugging.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic