create EJB using primary key class
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   daniel_wong
Posted On:   Sunday, April 28, 2002 12:35 PM

Dear Sir, I am looking for some "useful" examples for using primary key class in EJB, no matter is CMP or BMP. Could you please send me some useful examples? I am using such code for my ejbStore method, but there is an error for my preparedstatement, any problem with my sql statement?? String updateStatement = "update DATATBL set event = ? " + "where id = ? and date = ? and time = ?"; System.out.println("after created the update statement"); PreparedStatement prepStmt = con.prepareStatement(updateStatement); prepStmt.setString(1, event); prepStmt.setStr   More>>

Dear Sir,


I am looking for some "useful" examples for using primary key class in EJB, no matter is CMP or BMP. Could you please send me some useful examples?


I am using such code for my ejbStore method, but there is an error for my preparedstatement, any problem with my sql statement??




String updateStatement =

"update DATATBL set event = ? " +

"where id = ? and date = ? and time = ?";




System.out.println("after created the update statement");



PreparedStatement prepStmt =

con.prepareStatement(updateStatement);



prepStmt.setString(1, event);

prepStmt.setString(2, id);

prepStmt.setString(3, date.toString());

prepStmt.setString(4, time.toString());



int rowCount = prepStmt.executeUpdate();



prepStmt.close();



if (rowCount == 0) {

System.out.println("cannot store the row");

throw new EJBException("Storing row for id " +

id + " failed.");

}

}

   <<Less

Re: create EJB using primary key class

Posted By:   AlessandroA_Garbagnati  
Posted On:   Monday, April 29, 2002 01:44 AM

Daniel,

One possible reason is that the default conversion used by java from date/time to string isn't compatible with the one of your database.

I don't know what type of objects are date and time, but definitely you should consider using either prepStmt.setDate() (for date only), prepStmt.setTime() (for time only) and prepStmt.setTimestamp() (for date/time).


Check out the java.sql package documentation or the FAQs on here, for additional information. This topic has been covered many times.

About | Sitemap | Contact