on 06-04-2010 3:51 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Solved by reading SAP help portal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.