File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes This is driving me crazy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "This is driving me crazy" Watch "This is driving me crazy" New topic
Author

This is driving me crazy

xue shen
Greenhorn

Joined: Jul 05, 2002
Posts: 23
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

Joined: Jun 08, 2002
Posts: 18
hi
just check the field name plz


khurram shahood(Java Farmer)
xue shen
Greenhorn

Joined: Jul 05, 2002
Posts: 23
I checked the field name many times. I am completely baffled by this problem. Any insight from any body?
Ming Chen
Greenhorn

Joined: Mar 14, 2002
Posts: 13
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: This is driving me crazy
 
Similar Threads
problem in jsp and database connection
Error attempting to submit data via a form
servlets and sql
Connection with database Help
MySQL - add and remove username from table