cancel
Showing results for 
Search instead for 
Did you mean: 

OpenSQLException - object of type java.sql.Date is not normalized

brian_arthern2
Participant
0 Kudos

Hi,

I am attempting to code an SQL query in an EJB and get the following exception:

com.sap.sql.log.OpenSQLException: The object of type java.sql.Date with the value '2010-06-04 13:21:09.424' assigned to host variable 1 is not normalized. It must not contain time components in the time zone running the virtual machine. at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:85) at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:124) at com.sap.sql.jdbc.common.CommonPreparedStatement.setDate(CommonPreparedStatement.java:650) at......

Below is the code snippet I am using:

private static String selWQ = "Select * from ZZZZ_TABLE " +

"where DATEFROM >= ? " +

"and DATETO <= ? ";

public UsageRecord[] getRecords(Date fromDate,Date toDate)

{

UsageRecord[] ura = null;

String q = null;

ArrayList al = new ArrayList();

try

{

q = selWQ;

conn.open();

PreparedStatement p = conn.prepareStatement(q);

p.setDate(1, fromDate);

p.setDate(2,toDate);

ResultSet rs = p.executeQuery();

.......

I have a PreparedStatement and am using setDate to set the values. The fromDate and toDate parameters are of type java.sql.Date

Can someone please tell me what I am doing wrong and how to fix it?

thanks

Brian

Accepted Solutions (0)

Answers (3)

Answers (3)

brian_arthern2
Participant
0 Kudos

As requested, here is an example of what I used to resolve this:

PreparedStatement p = conn.prepareStatement(q);

SimpleDateFormat ddf = new SimpleDateFormat("yyyy-MM-dd");

String sFrom = ddf.format(new java.util.Date(fromDate));

String sTo = ddf.format(new java.util.Date(toDate));

p.setDate(1, java.sql.Date.valueOf(sFrom));

p.setDate(2, java.sql.Date.valueOf(sTo));

ResultSet rs = p.executeQuery();

fromDate and toDate are parameters of type long...

regards

Brian

brian_arthern2
Participant
0 Kudos

Solved by reading SAP help portal

ReenaWadhwa
Advisor
Advisor
0 Kudos

Hi Brian,

I am also facing the same issue. Can you please help me here.

Thanks!!!

rolf_paulsen
Active Participant
0 Kudos

Hi Brian,

did you check this answered post:

[;

Regards

Rolf