This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes getting  java.sql.Timestamp exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getting  java.sql.Timestamp exception" Watch "getting  java.sql.Timestamp exception" New topic
Author

getting java.sql.Timestamp exception

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Please look at the code below :

String bot_id = "";
String session_id = "";
String domain = "";
String signal = "";
String kick_off = "";
java.util.Date bot_alarm_timestamp = null;
String next_node = "";
String next_case = "";
String bot_level = "";
String bot_message = "";
String active_converse = "";
String reply_text = "";
java.util.Date send_timestamp= null;
java.util.Date delivery_timestamp = null;

try {
//Instantiate the SynthDBAccessor interface.
dba = new SynthDBAccessor();

dbQuery1 = "SELECT * FROM MJST_PLAYER_BOTS WHERE PLAYER_ID = '"+playerId+"'";

col1 = dba.retrieveData(dbQuery1);

while ( col1.next() ) {

bot_id = col1.getString("BOT_ID");
session_id = col1.getString("SESSION_ID");
domain = col1.getString("DOMAIN");
signal = col1.getString("SIGNAL");
kick_off = col1.getString("KICK_OFF");
bot_alarm_timestamp = col1.getDate("BOT_ALARM_TIMESTAMP");

// I am using my own DB access classes, and col1.getDate() return java.util.Date

next_node = col1.getString("NEXT_NODE");
next_case = col1.getString("NEXT_CASE");
bot_level = col1.getString("BOT_LEVEL");
bot_message = col1.getString("BOT_MESSAGE");
active_converse = col1.getString("ACTIVE_CONVERSE");
reply_text = col1.getString("REPLY_TEXT");
send_timestamp = col1.getDate("SEND_TIMESTAMP");
delivery_timestamp = col1.getDate("DELIVERY_TIMESTAMP");

dbQuery2 = "SELECT * FROM BKP_PLAYER_BOTS WHERE BOT_ID = '"+bot_id+"'";

col2 = dba.retrieveData(dbQuery2);

if ( ! ( col2.next() ) ) {

con = dba.getConnection();

insertSQL = "INSERT INTO BKP_PLAYER_BOTS ( PLAYER_ID, BOT_ID, SESSION_ID, DOMAIN, SIGNAL, KICK_OFF, "+
"BOT_ALARM_TIMESTAMP, NEXT_NODE, NEXT_CASE, BOT_LEVEL, BOT_MESSAGE, ACTIVE_CONVERSE, REPLY_TEXT, "+
"SEND_TIMESTAMP, DELIVERY_TIMESTAMP, PLAYER_LEVEL ) values(?, ?, ?, ?, ?, ?,?.?,?,?,?,?,?,?,?,?)";
pstmt = con.prepareStatement(insertSQL);
pstmt.setString(1, playerId);
pstmt.setString(2, bot_id);
pstmt.setString(3, session_id);
pstmt.setString(4, domain);
pstmt.setString(5, signal);
pstmt.setString(6, kick_off);
pstmt.setDate(7, ( java.sql.Date ) bot_alarm_timestamp);
pstmt.setString(8, next_node);
pstmt.setString(9, next_case);
pstmt.setString(10, bot_level);
pstmt.setString(11, bot_message);
pstmt.setString(12, active_converse);
pstmt.setString(13, reply_text);
pstmt.setDate(14, ( java.sql.Date ) send_timestamp);
pstmt.setDate(15, ( java.sql.Date ) delivery_timestamp);
pstmt.setString(16, playerLevel);

insertCount = pstmt.executeUpdate();

if(insertCount <= 0)<br /> throw new Exception("Problem inserting new bots data into bkp_player_bots");<br /> <br /> } // close of if<br /> <br /> <br /> } // close of while<br /> <br /> } // close of try<br /> <br /> When I execute this code, I get the following exception<br /> <br /> Tue May 01 23:25:12 GMT+00:00 2001:<I> <ServletContext-Servlets> weblogic.servlet.JSPServlet: Generated java file: /opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_SetPlayerBots.java<br /> Exception caught : java.sql.Timestamp<br /> The structure of the table BKP_PLAYER_BOTS is as follows :<br /> <br /> SQL rjanapareddy@MJSTRND> desc BKP_PLAYER_BOTS;
Name Null? Type
----------------------------------------- -------- ----------------------------
PLAYER_ID NOT NULL VARCHAR2(20)
BOT_ID NOT NULL VARCHAR2(20)
SESSION_ID VARCHAR2(50)
DOMAIN VARCHAR2(20)
SIGNAL VARCHAR2(20)
KICK_OFF VARCHAR2(3)
BOT_ALARM_TIMESTAMP DATE
NEXT_NODE VARCHAR2(20)
NEXT_CASE VARCHAR2(20)
BOT_LEVEL VARCHAR2(20)
BOT_MESSAGE VARCHAR2(2000)
ACTIVE_CONVERSE NOT NULL VARCHAR2(3)
REPLY_TEXT VARCHAR2(500)
SEND_TIMESTAMP DATE
DELIVERY_TIMESTAMP DATE
PLAYER_LEVEL NOT NULL VARCHAR2(20)

Can some one suggest me why I am getting this exception ?


SCJP, SCJD, SCWCD, SCBCD, SCEA
Daniel Dunleavy
Ranch Hand

Joined: Mar 13, 2001
Posts: 276
try setTimestamp instead of setDate?
Dan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting java.sql.Timestamp exception