This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "This is driving me crazy" Watch "This is driving me crazy" New topic

This is driving me crazy

xue shen

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", "");
PreparedStatement addRecord;
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', '')");
addRecord.setString( 1, newuser.getUsername() );
addRecord.setString( 2, newuser.getPassword() );
addRecord.setString( 3, newuser.getEmail() );
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)

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

khurram shahood(Java Farmer)
xue shen

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

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:
subject: This is driving me crazy
It's not a secret anymore!