Jdbc Timestamp advise
hi all,
I'm novice using Timestamp and I've the following problem:
I need to do a query that show me as result a specific rows in a date's range but when i try to execute the query I got a error because i must to send to db a Timestamps values and I'm sending a java.util.Date or String fields not Timestamps.
How I can create a Timestamp for my start date (b.e. '01/01/2003') and another for my ends date (b.e. '31/12/2003'), or I can do for resolve this problem.
thanks for advise me?
From the JavaDoc for java.sql.Timestamp:
public Timestamp(long time)
Constructs a Timestamp object using a milliseconds time value.
From the JavaDoc for java.util.Date:
public long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Similar Messages
-
Jdbc timestamp error on getting timezone
Hello
I changed my application from J2EE standalone container 9.0.4 to the new OAS 10.1.0.2.
Now I have a problem with timestamp CMP-Attributes.
When I set a timestamp attribut and get it back I have the following exception. The JDBC driver seems to convert the timestamp variable with a sun util for timezones.
I allready set the timezone to real value on the database and with -Duser.timezone Options for the VM.
The Exception is:
java.lang.IllegalArgumentException
at sun.util.calendar.ZoneInfo.getOffset(ZoneInfo.java:322)
at oracle.jdbc.driver.DateTimeCommonAccessor.zoneOffset(DateTimeCommonAccessor.java:370)
at oracle.jdbc.driver.DateTimeCommonAccessor.getMillis(DateTimeCommonAccessor.java:411)
at oracle.jdbc.driver.TimestampAccessor.getTimestamp(TimestampAccessor.java:153)
at oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResultSetImpl.java:750)
at com.evermind.sql.ResultSetBCELProxy.getTimestamp(ResultSetBCELProxy.java:297)
at FaelleLocal_EntityBeanWrapper30.loadStateCorePKNonPartial(FaelleLocal_EntityBeanWrapper30.java:44476)
at EbenenLocal_FaelleLocal_ORCollection172.getObjects(EbenenLocal_FaelleLocal_ORCollection172.java:93)
at com.evermind.server.ejb.ORCollection.contains(ORCollection.java:273)
at com.evermind.server.ejb.ORCollection.add(ORCollection.java:228)
at com.evermind.server.ejb.ORCollection.add(ORCollection.java:355)
at FaelleEJB_PersistenceManager31.__core__setebene(FaelleEJB_PersistenceManager31.java:1083)
at FaelleEJB_PersistenceManager31.setEbene(FaelleEJB_PersistenceManager31.java:1109)
at FaelleLocal_EntityBeanWrapper30.setEbene(FaelleLocal_EntityBeanWrapper30.java:11182)
at com.rehabnet.rehabcycle.server.util.TOFactory.setFallTO(TOFactory.java:693)
at com.rehabnet.rehabcycle.server.impl.ResourceManagerSessionEJB.setFall(ResourceManagerSessionEJB.java:1411)
at ...
Thanks for your help.
best
chrueHello
Thanks for your help.
I solved the problem.
We changed the column type from date to timestamp.
While doing this oracle produces illegal timestamp values with negativ milliseconds. When the bean reads the data he convert the time to the java time with the timezone. The IllegalArgumentException was throwing because of the negativ millisecond part.
best
chrue. -
hello all,,
how r u ?
it is My Problem
when i select a date and a number from Datebase in TOAD Application as
select date1, load from c_day
the result is :
date1 ( type Date ) load ( type Number)
DD/MM/YYYY
01/05/2007 20.30
02/05/2007 16.21
03/05/2007 65.014
04/05/2007 20.30
when inserting this query in Java Code as:
Timestamp t = null;
BigDecimal b = null;
String sql = "select date1, load from c_day";
PreparedStatement stm = con.prepareStatement(sql);
ResultSet rs = stm.executeQuery();
while(rs.next){
t = rs.getTimestamp(1);
b = rs.getBigDecimal(2);
System.out.println("date : " + t.toString() + " , load = " + b.doubleValue());
// some dates is wrong .
Result
date : 01/05/2007 00:00:00 , load = 20.30
date : 02/05/2007 00:00:00 , load = 16.21
[i]date : 02/05/2007 23:00:00 , load = 65.014
date : 04/05/2007 00:00:00 , load = 20.30
so is this a bug in Java or is there is any Solution ???hello all,,
how r u ?
it is My Problem
when i select a date and a number from Datebase in
TOAD Application as
elect date1, load from c_day
the result is :
date1 ( type Date ) load ( type
Number)
DD/MM/YYYY
01/05/2007 20.30
02/05/2007
16.21
65.014
20.30
ava Code as:
Timestamp t = null;
BigDecimal b = null;
String sql = "select date1, load from c_day";
PreparedStatement stm = con.prepareStatement(sql);
ResultSet rs = stm.executeQuery();
while(rs.next){
t = rs.getTimestamp(1);
b = rs.getBigDecimal(2);
System.out.println("date : " + t.toString() + " ,
load = " + b.doubleValue());
// some dates is wrong .
Result
date : 01/05/2007 00:00:00 , load = 20.30
date : 02/05/2007 00:00:00 , load = 16.21
[i]date : 02/05/2007 23:00:00 , load = 65.014
date : 04/05/2007 00:00:00 , load = 20.30
so is this a bug in Java or is there is any Solution
???Check your data. It could be that TOAD is using a different time zone or DST value to Java, and that '2/5/2007 2300' turns into '3/5/2007'.
David Rolfe -
Hello all,
How to convert java.Sql. timestamp yyyy-mm-dd HH:MM:SS.nanosec to yyyy-mm-dd HH:MM:SS format.
Thanksshreenivasa wrote:
My code is:-
String cDt = "SELECT NOW()";
ResultSet curdate = st.executeQuery(cDt);
while(curdate.next()){
cdt = curdate.getTimestamp(1);
String updateString = "UPDATE `1` SET startdate = 'cdt' " +
"WHERE idchecklist LIKE " + chkId;
st.executeUpdate(updateString);
The output is 2008-04-25 18:28:00.0
Unable to insert into a Mysql Database to a filed which is timestamp. Pls provide me how to convert this to MYSQL format.You should use PreparedStatement. -
How to put date&time into a variable from a database?
In an Oracle table, myDateColumn is 2002-06-25 17:40:55. I can't put it into a variable.
java.text.SimpleDateFormat dF=new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
rs=stmt.executeQuery("select myDateColumn from myTable");
rs.next()
System.out.println(rs.getString(1)); // 2002-06-25 17:40:55 is output
java.util.Date myDate=rs.getDate(1);
out.println(dF.format(myDate)); // 25/06/2002 00:00:00 is output
java.util.Date myDate=rs.getTime(1);
out.println(dF.format(myDate)); // 01/01/1970 17:40:55 is output
My question is: How should I put this date (both date and time) into a variable, myDate?There are three JDBC types relating to time:
1] The JDBC DATE type represents a date consisting of day, month, and year. The corresponding SQL DATE type is defined in SQL-92, but it is implemented by only a subset of the major databases. Some databases offer alternative SQL types that support similar semantics.
2] The JDBC TIME type represents a time consisting of hours, minutes, and seconds. The corresponding SQL TIME type is defined in SQL-92, but it is implemented by only a subset of the major databases. As with DATE, some databases offer alternative SQL types that support similar semantics.
3] The JDBC TIMESTAMP type represents DATE plus TIME plus a nanosecond field. The corresponding SQL TIMESTAMP type is defined in SQL-92, but it is implemented by only a very small number of databases.
In ur case pls use:
java.sql.Timestamp
good luck !
...san :--) -
Error when reading BLOB field from Oracle usin Toplink
We experience a very annoying problem when trying to read a BLOB
field from Oracle 8.1.6.2.0 using TOPLink 3.6.3. I have attached the
exception stack trace that is reported to the console. As far as I can
judge a fault at oracle.sql.LobPlsqlUtil.plsql_length() happens first and
then at TOPLink.Private.DatabaseAccess.DatabasePlatform.convertObject().
The exception is permanently repeating that is very critical for us.
ServerSession(929808)--Connection(5625701)--SELECT LOBBODY, ID, LABEL, FK_OBJECT_ID, FK_OBJECTTYPE FROM NOTE WHERE (ID = 80020)
INTERNAL EXCEPTION STACK:
java.lang.NullPointerException
at oracle.sql.LobPlsqlUtil.plsql_length(LobPlsqlUtil.java:936)
at oracle.sql.LobPlsqlUtil.plsql_length(LobPlsqlUtil.java:102)
at oracle.jdbc.dbaccess.DBAccess.lobLength(DBAccess.java:709)
at oracle.sql.LobDBAccessImpl.length(LobDBAccessImpl.java:58)
at oracle.sql.BLOB.length(BLOB.java:71)
at TOPLink.Private.Helper.ConversionManager.convertObjectToByteArray(ConversionManager.java:309)
at TOPLink.Private.Helper.ConversionManager.convertObject(ConversionManager.java:166)
at TOPLink.Private.DatabaseAccess.DatabasePlatform.convertObject(DatabasePlatform.java:594)
at TOPLink.Public.Mappings.SerializedObjectMapping.getAttributeValue(SerializedObjectMapping.java:43)
at TOPLink.Public.Mappings.DirectToFieldMapping.valueFromRow(DirectToFieldMapping.java:490)
at TOPLink.Public.Mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:808)
at TOPLink.Private.Descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:173)
at TOPLink.Private.Descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:325)
at TOPLink.Private.Descriptors.ObjectBuilder.buildObjectsInto(ObjectBuilder.java:373)
at TOPLink.Public.QueryFramework.ReadAllQuery.execute(ReadAllQuery.java:366)
at TOPLink.Public.QueryFramework.DatabaseQuery.execute(DatabaseQuery.java:406)
I have started the application with Oracle JDBC logging on and found that the problem may originate in a possible lack of syncronization in the pooled connection implementation:
DRVR FUNC OracleConnection.isClosed() returned false
DRVR OPER OracleConnection.close()
DRVR FUNC OracleConnection.prepareCall(sql)
DRVR DBG1 SQL: "begin ? := dbms_lob.getLength (?); end;"
DRVR FUNC DBError.throwSqlException(errNum=73, obj=null)
DRVR FUNC DBError.findMessage(errNum=73, obj=null)
DRVR FUNC DBError.throwSqlException(reason="Logical handle no longer valid",
SQLState=null, vendorCode=17073)
DRVR OPER OracleConnection.close()
so the prepareCall() is issued against an already closed connection and the
call fails.
I assume we have been using a JDBC 2.0 compliant driver. We tried out
drivers that Oracle supplies for 8.1.6, 8.1.7 versions. To be true I
couldn't find any information about the JDBC specification they conform to. Does it
mean that these drivers may not be 100%-compatible with JDBC 2.0 Spec?
How can I find out if they are 2.0 compliant?
Also I have downloaded Oracle 9.2.0.1 JDBC drivers. This seemed to work
fine until we found another incompatibility which made us return back to
8.1.7 driver:
UnitOfWork(7818028)--Connection(4434104)--INSERT INTO STATUSHISTORY (CHANGEDATE, FK_SET_STATUS_ID) VALUES ({ts '2002-10-17 16:46:54.529'}, 2)
INTERNAL EXCEPTION STACK:
java.sql.SQLException: ORA-00904: invalid column name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.jav
a:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java
:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatemen
t.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepare
dStatement.java:589)
at TOPLink.Private.DatabaseAccess.DatabaseAccessor.executeDirectNoSelect(
DatabaseAccessor.java:906)
at TOPLink.Private.DatabaseAccess.DatabaseAccessor.executeNoSelect(Databa
seAccessor.java:960)
at TOPLink.Private.DatabaseAccess.DatabaseAccessor.executeCall(DatabaseAc
cessor.java:819)
at TOPLink.Public.PublicInterface.UnitOfWork.executeCall(UnitOfWork.java:Hello Yury,
I believe the problem is that TopLink's ServerSession by default executes read queries concurrently on the same connection. It does this to reduce the number of required connections for the read connection pool. Normally this is a good concurrency optimization, however some JDBC drivers have issues when this is done. I had thought that with Oracle JDBC 8.1.7 this issue no longer occurred, but perhaps it is only after version 9. I believe that the errors were only with the thin JDBC driver, not the OCI, so using the OCI driver should also resolve the problem. Using RAW instead of BLOB would also work.
You can configure TopLink to resolve this problem through using exclusive read connection pooling.
Example:
serverSession.useExclusiveReadConnectionPool(int minNumerOfConnections, int maxNumerOfConnections);
This will ensure that TopLink does not to try to concurrently execute read queries on the same connection.
I'm not exactly sure what your second problem with the 9.x JDBC drivers is. From the SQL and stack trace it would seem that the driver does not like the JDBC timestamp syntax. You can have TopLink print timestamp in Oracle's native SQL format to resolve this problem.
Example:
serverSessoin.getLogin().useNativeSQL();
Make sure you configure your server session before you login, or if using the TopLink Session Manager perform the customizations through a SessionEventListener-preLogin event. -
Hi, could anybody give me documentation to the Oracle.jbo.Domain.Date class ?
Why this is not documented?
why give this class with the same name than java.util.Date ? it really turns coding hard:
oracle.jbo.Domain.Date d1 = getMyDate();
java.util.Date d2 = d1.toDate();
it's really disgusting.
nullThere is a bug logged regarding the missing javadoc in JDev 3.1. There was documentation for the Date in JDev 3.0. Apparently we missed it somehow. Below is the javadoc from JDev 3.0. Sorry for the long post, but I hope it helps.
oracle.jbo.domain
Class Date
java.lang.Object
|
+--oracle.sql.Datum
|
+--oracle.sql.DATE
|
+--oracle.jbo.domain.Date
public class Date
extends oracle.sql.DATE
implements DomainInterface, oracle.sql.CustomDatum, java.io.Serializable
An encapsulation of Oracle SQL DATE objects as immutable Domain objects.
Date objects consist of data (a byte array) and a Domain type code. Domain dates extend SQL dates by being convertable to and from JDBC values.
Since:
JDevloper 3.0
See Also:
Serialized Form
Fields inherited from class oracle.sql.DATE
BDA, BDAL, BDT, BHR, BHRL, BMN, BMNL, BMO, BMOL, BSC, BSCL, BYR, BYRL, HRZER0, MIZERO, MSD, SEZERO, YR0
Constructor Summary
Date()
Creates a default Date Domain object.
Date(byte[] value)
Internal: Applications should not invoke this method.
Date(Date value)
Creates a Date identical to an existing Date.
Date(java.sql.Date value)
Creates a Date Domain object from a JDBC Date.
Date(oracle.sql.DATE value)
Creates a Date Domain object from an Oracle SQL DATE.
Date(java.lang.Object value)
Creates a Date Domain object from a JDBC Object.
Date(java.lang.String value)
Creates a Date Domain object from a Java String.
Date(java.sql.Time value)
Creates a Date Domain object from a JDBC Time object.
Date(java.sql.Timestamp value)
Creates a Date Domain object from a JDBC Timestamp object.
Method Summary
oracle.sql.DATE addJulianDays(int julianDay, int julianSec)
oracle.sql.DATE addMonths(int months)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
Number diffInMonths(Date date)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
oracle.sql.NUMBER diffInMonths(oracle.sql.DATE date)
boolean equals(java.lang.Object other)
Tests this for equality with another object.
static oracle.sql.DATE fromJulianDays(int julianDay, int julianSec)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
static oracle.sql.DATE fromText(java.lang.String datestr, java.lang.String fmt, java.lang.String lang)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
static oracle.sql.DATE getCurrentDate()
Overrides the Oracle SQL method of the same name to return a Date Domain object.
static oracle.sql.CustomDatumFactory getCustomDatumFactory()
Internal: Applications should not invoke this method.
java.lang.Object getData()
Converts this to a JDBC Timestamp object.
int hashCode()
Computes a hash code for this.
oracle.sql.DATE lastDayOfMonth()
Overrides the Oracle SQL method of the same name to return a Date Domain object.
static void main(java.lang.String[] argv)
Internal: Applications should not invoke this method.
oracle.sql.DATE round(java.lang.String prec)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
oracle.sql.DATE setDayOfWeek(int day)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
oracle.sql.Datum toDatum(oracle.jdbc.driver.OracleConnection conn)
Internal: Applications should not invoke this method.
oracle.sql.NUMBER toNumber()
java.lang.String toString()
Converts this to a textual representation.
oracle.sql.DATE truncate(java.lang.String prec)
Methods inherited from class oracle.sql.DATE
checkValidity, compareTo, dateValue, diffInJulianDays, isConvertibleTo, makeJdbcArray, numberToJulianDays, stringValue, timestampValue, timeValue, toBytes, toBytes, toBytes, toBytes, toBytes, toDate, toJdbc, toJulianDays, toString, toText, toTime, toTimestamp
Methods inherited from class oracle.sql.Datum
asciiStreamValue, bigDecimalValue, binaryStreamValue, booleanValue, byteValue, characterStreamValue, doubleValue, floatValue, getBytes, getLength, getStream, intValue, longValue, setBytes, setShareBytes, shareBytes
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
Constructor Detail
Date
public Date()
Creates a default Date Domain object.
This constructor does not create a null date: use one of the NullValue() constructors.
Date
public Date(byte[] value)
Internal: Applications should not invoke this method.
Creates a Date Domain object from the given byte array.
Parameters:
value - a value returned by a previous call to getBytes() on an SQL object compatable with Date.
Date
public Date(oracle.sql.DATE value)
Creates a Date Domain object from an Oracle SQL DATE.
Parameters:
value - a DATE SQL object.
Date
public Date(Date value)
Creates a Date identical to an existing Date.
Parameters:
value - a Date Domain object.
Date
public Date(java.sql.Date value)
Creates a Date Domain object from a JDBC Date.
Parameters:
value - a DATE SQL object.
Date
public Date(java.sql.Time value)
Creates a Date Domain object from a JDBC Time object.
Parameters:
value - a Time SQL object.
Date
public Date(java.sql.Timestamp value)
Creates a Date Domain object from a JDBC Timestamp object.
Parameters:
value - a Time SQL object.
Date
public Date(java.lang.Object value)
throws java.sql.SQLException
Creates a Date Domain object from a JDBC Object.
Parameters:
value - an Object that is an instance of Date, Time, Timestamp, or String.
Throws:
java.sql.SQLException - if the object is not of one of the recognized classes.
Date
public Date(java.lang.String value)
Creates a Date Domain object from a Java String.
Parameters:
value - a textual representation of a Date.
Method Detail
getCustomDatumFactory
public static oracle.sql.CustomDatumFactory getCustomDatumFactory()
Internal: Applications should not invoke this method.
Initializes the Date Domain.
This method is invoked when JBO is initialized. Applications should not call this method directly.
Returns:
the CustomDatumFactory for the Date Domain.
toDatum
public oracle.sql.Datum toDatum(oracle.jdbc.driver.OracleConnection conn)
throws java.sql.SQLException
Internal: Applications should not invoke this method.
Converts this Date Domain object back into an SQL DATE object.
Specified by:
toDatum in interface oracle.sql.CustomDatum
Parameters:
conn - Not used.
Returns:
A Datum containing DATE object.
Throws:
SQLException - Never.
getData
public java.lang.Object getData()
Converts this to a JDBC Timestamp object.
Specified by:
getData in interface DomainInterface
Tags copied from interface: DomainInterface
Returns:
a formatted value object.
toString
public java.lang.String toString()
Converts this to a textual representation.
Overrides:
toString in class java.lang.Object
equals
public boolean equals(java.lang.Object other)
Tests this for equality with another object. The argument is converted to a Date object, if necessary.
Overrides:
equals in class oracle.sql.Datum
Parameters:
other - an arbitrary Object.
Returns:
true if conversion was successful and the converted argument is identical to this.
hashCode
public int hashCode()
Computes a hash code for this.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this.
addJulianDays
public oracle.sql.DATE addJulianDays(int julianDay,
int julianSec)
Overrides:
addJulianDays in class oracle.sql.DATE
Returns:
a Date Domain object.
addMonths
public oracle.sql.DATE addMonths(int months)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
Overrides:
addMonths in class oracle.sql.DATE
See Also:
"oracle.sql.DATE"
diffInMonths
public Number diffInMonths(Date date)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
See Also:
"oracle.sql.DATE"
diffInMonths
public oracle.sql.NUMBER diffInMonths(oracle.sql.DATE date)
Overrides:
diffInMonths in class oracle.sql.DATE
getCurrentDate
public static oracle.sql.DATE getCurrentDate()
Overrides the Oracle SQL method of the same name to return a Date Domain object.
See Also:
"oracle.sql.DATE"
fromJulianDays
public static oracle.sql.DATE fromJulianDays(int julianDay,
int julianSec)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
See Also:
"oracle.sql.DATE"
fromText
public static oracle.sql.DATE fromText(java.lang.String datestr,
java.lang.String fmt,
java.lang.String lang)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
See Also:
"oracle.sql.DATE"
lastDayOfMonth
public oracle.sql.DATE lastDayOfMonth()
Overrides the Oracle SQL method of the same name to return a Date Domain object.
Overrides:
lastDayOfMonth in class oracle.sql.DATE
See Also:
"oracle.sql.DATE"
round
public oracle.sql.DATE round(java.lang.String prec)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
Overrides:
round in class oracle.sql.DATE
See Also:
"oracle.sql.DATE"
setDayOfWeek
public oracle.sql.DATE setDayOfWeek(int day)
Overrides the Oracle SQL method of the same name to return a Date Domain object.
Overrides:
setDayOfWeek in class oracle.sql.DATE
See Also:
"oracle.sql.DATE"
toNumber
public oracle.sql.NUMBER toNumber()
Overrides:
toNumber in class oracle.sql.DATE
Returns:
a Date Domain object.
truncate
public oracle.sql.DATE truncate(java.lang.String prec)
Overrides:
truncate in class oracle.sql.DATE
Returns:
a Date Domain object.
main
public static void main(java.lang.String[] argv)
throws java.sql.SQLException
Internal: Applications should not invoke this method.-- Brian -
Timestamp issue in JDBC sender adapter
All,
Database is sending the timestamp in th below format,
28-06-2010 12:41:20
but SAP PI JDBC adapter is converting the same data as below.
28-06-2010 12:41:20.0
we are getting an extra ZERO, can any one tell me the solution for not getting extra ZERO.
Thank You,
MadhavTry to Use JDBC Date Function in Select Query .
to_char( Coloumn_name , 'DD-MON-YYYY HH:MI:SS')
it will forcefully get the date in following format .. but one thing to remeber this will covert your date into string format ..so to catch the following date on sender Message Type , it may require to create that structure with string type.
Regards
Prabhat Sharma(Dragon). -
JDBC Adapter - Update SQL Statement - Timestamp
Hi All,
I'm using a JDBC Sender channel to bring information from a database, when I bring the data I want to UPDATE a field inserting the date and time (timestamp) when you got the info.
Sender Communication Channel: JDBC
Query SQL Statement: SELECT * FROM PI_Factory
Update SQL Statement: ????????
Could you tell me how to do this?Hi
please try the below query in Update sql statement
update table_name set fieldname = systimestamp where .....
or
update table_name set fieldname = current_timestamp where .....
Regards
Ramg. -
Problem with SDO_FILTER combined with Timestamp and Order By using JDBC
I'm having a problem with using SDO_FILTER. I've included a test driver below. It seems that I'm having a problem with combining the SDO_FILTER, Timestamp, ORDER BY and a nested table using the Oracle 11.1.0.7.0 driver against Oracle 11g. The below query queryNoWork results in the following error:
Caused by: java.sql.SQLException: ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "MDSYS.SDO_3GL", line 1320
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1186)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3488)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:299)
All of the other query variations seem to work. The GEOM column referenced is a Linestring that has only 2 points, start and end. Any help on this would be greatly appreciated. Thanks!
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
public class QueryTester
public static void main(String[] args)
try
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
ArrayList<Object> queryParameters = new ArrayList<Object>();
queryParameters.add(new BigDecimal(0));
queryParameters.add(new Double(0));
queryParameters.add(new BigDecimal(180));
queryParameters.add(new Double(90));
queryParameters.add(new java.sql.Date(sdf.parse("2005-12-25").getTime()));
queryParameters.add(new java.sql.Date(sdf.parse("2005-12-26").getTime()));
BigDecimal one = new BigDecimal(1);
DriverManager.registerDriver((Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
Enumeration<Driver> drivers = DriverManager.getDrivers();
while(drivers.hasMoreElements())
System.out.println(drivers.nextElement().getClass().getName());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxxx:1521:xxxx", "xxxx", "xxxx");
String queryNoWork = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks0 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_relate(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks1 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= TO_TIMESTAMP('2005-12-25','YYYY-MM-DD') and START_DATE < TO_TIMESTAMP('2005-12-26','YYYY-MM-DD')) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks2 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ) a) where rowcount between 1 and 30000";
String queryWorks3 = "select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID";
String query = queryWorks0;
PreparedStatement s = conn.prepareStatement(query);
int parameterIndex = 0;
for (Object object : queryParameters) {
if (object instanceof Timestamp)
s.setDate(++parameterIndex, (Date) object);
else
s.setObject(++parameterIndex, object);
s.execute();
ResultSet results = s.getResultSet();
results.next();
System.out.println("executed query - " + results.getLong(1));
catch (Exception e)
e.printStackTrace();
}Is the TRACK_SEGMENTS table partitioned ?
It looks like in the case where the SQL does not work, it is not using the Spatial index. So can you add some index hints
in the query to force it to use the spatial index TRACK_SEGMENTS table ?
siva -
Map java.sql.Timestamp to JDBC-MySQL TIMESTAMP?
Java provides the java.sql.Timestamp class specifically to be able to make
use of the greater-accuracy timestamps provided in JDBC and underlying
datastores. Is there a way to set up a Kodo mapping file such that a
persistent class with a java.sql.Timestamp field, has this field map to a
TIMESTAMP field in the underlying database table?
Thanks,
-- BryanYes, with a custom field mapping. See the example of a custom field
mapping for java.sql.Date in samples/ormapping. A mapping for timestamp
would be almost exactly the same. -
DATE and TIMESTAMP problem - fixable with 11.1 JDBC Driver?
I'm adding some queries to an older part of our code base and while reading through the documentation for one of the classes I found that we weren't using our normal Hibernate queries because we needed to ensure that we weren't sending Timestamps to Oracle. Apparently the Timestamp would be converted to a Date because the column in the database was of type DATE. This was causing problems because the DATE column's index was being ignored and the table contains millions of records.
The Oracle FAQ seems to indicate that this has been fixed in the 11.1 JDBC drivers. I know that I can use 11.1 JDBC drivers with a 10.2.0 database, but will it use the new 11.1 mappings for DATE and TIMESTAMP or the old 10.2.0 mappings? Oracle FAQ page: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01Oracle FAQ page: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_01
Well obviously that was really stupid.
I'm adding some queries to an older part of our code base and while reading through the documentation for one of the classes I found that we weren't using our normal Hibernate queries because we needed to ensure that we weren't sending Timestamps to Oracle. Apparently the Timestamp would be converted to a Date because the column in the database was of type DATE. This was causing problems because the DATE column's index was being ignored and the table contains millions of records.
Not sure I follow that logic.
If the value was going into the database then it would update the index.
From that only one of the following could be true.
1. It wasn't going into the database.
2. It was being truncated to a date.
The Oracle FAQ seems to indicate that this has been fixed in the 11.1 JDBC drivers. I know that I can use 11.1 JDBC drivers with a 10.2.0 database, but will it use the new 11.1 mappings for DATE and TIMESTAMP or the old 10.2.0 mappings? I would agree with your interpretation of the FAQ.
And I would then follow it up by testing both with the old driver and the new. -
Problems using FP Advise Timestamp
I'm having problems using the timestamp from the FP Advise vi - dates/times way out from current date/time. I am using FP1600 and have FW 3.00.
I've seen some comments re time sync of the FP Server but not sure what this relates to.
Any help would be appreciated.
Thanks,
Niel.Niel,
Sorry for the confusion. The Time Service that the FP-1600 uses is the Lookout Time Synchronization Services. The Lookout Time Syncrhonization services debuted with Lookout 4.0 and shortly thereafter in FieldPoint Explorer 2.0. They are also distributed with later versions of those two products and now with LabVIEW-Data Logging and Supervisory Control module. The set-up of the Time Server is as simple as installing any of the above products. The Time Synchronization Server is installed as a Service and should always be available to any computer or device that is trying to synchronize to it.
A Time Server is a computer that is running the Lookout Time Synchronization Service as installed by any of the above mentioned products. The primary m
ethod of configuring a FP-1600 to use the Time Server is the Time Server IP Address assignment box which is located in the window where all of the FP-1600's ethernet parameters is located. It is strongly recommended that the Time Server be assigned a static IP address as the FP-1600 modules do not support DHCP. If you assign a FP-1600 to look at a particular IP address as it's Time Server, and due to DHCP it's changed it's address, then the FP-1600 is unable to synchronize it's clock. An important note is that even when a FP-1600 fails to synchronize it's clock, the delta's on the time-stamps will still be accurate even though the absolute date/time is incorrect.
Regards,
Aaron -
TimeStamp in Stored Procedure for JDBC adapter
Hi,
I have a Date Timestamp field (DD/MM/YYYY HH:MM:SS) in my stored procedure (target system), how do I pass an empty value when there is no date coming from the source system.
I am able to send the date field in the format when I get the date timestamp field in the source message but sometimes the date field will be empty in the source message, where in I have a issue to pass to stored procedure.
Error details - java.sql.SQLException: ORA-01830: date format picture ends before converting entire input string ORA-06512: at line 1
Thanks.
Yeshwanthbut sometimes the date field will be empty in the source message, where in I have a issue to pass to stored procedure.
Why not to avoid creating the DATE field in the target when the source is empty or not present? Just make a check on the source field....check if it is not-blank and then only create the target node....if the source field is blank then the target wont be created and hence wont be inserted into the DB....check if this works for you.
Also check the XML Schema Interpreter (Interpretation of Empty String Values) section from this help section:
http://help.sap.com/saphelp_nw70/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/content.htm
Regards,
Abhishek.
Edited by: abhishek salvi on Jul 16, 2010 3:23 PM -
Importing timestamp columns appears to use to_date instead of to_timestamp
I'm trying to import data (using the latest version 1.5.4 with Patch 2 applied) to an Oracle 10g database that contains timestamp columns. The input data has times with fractional (millisecond) values The data was exported using SQL Developer from a Sybase database and the timestamp format in the Excel (xls) file is YYYY-MM-DD HH24:MI:SS.FF3. When I specify this format for the TIMESTAMP columns on the import screens, the importer generates an insert statement like this:
INSERT INTO A (TMS) VALUES (to_date('2008-12-049 12:12:39.967', 'YYYY-MM-DD HH24:MI:SS.FF3'));
This command fails to execute with this error:
Error report:
SQL Error: ORA-01821: date format not recognized
01821. 00000 - "date format not recognized"
*Cause:
*Action:
I found that if to_timestamp is used instead of to_date, there is no issue inserting the row with the correct time precision. The question I have is why isn't SQL Developer using to_timestamp for importing a TIMESTAMP column, and should it?
Any advise woudl be appreciated.
ThanksIn 1.5.4 I see a bug where the "Format" field doesn't show up in the page in the import wizard, preventing the user from entering a mask when the column type is TIMESTAMP. This has been fixed in the code line under development and should be available when 2.1 gets released.
To give you a bit more detail on the confusing DATE/TIMESTAMP behaviour...
SQL Developer misrepresenting date as timestamp and vice versa stems from the behaviour of the Oracle JDBC driver. Following are the details I obtained from the JDBC team when I raised a bug("WRONG VALUE RETURNED FOR GETCOLUMNTYPE FOR DATE COLUMN ") on them:-
oracle.jdbc.mapDateToTimestamp is by default set
to true to indicate reporting DATE column as TIMESTAMP type. To turn off, pass
-Doracle.jdbc.mapDateToTimestamp=false" at the command line.
To effect this option in SQL Developer, you can add an AddVMOption -Doracle.jdbc.mapDateToTimestamp=false
A bit more history on the option:
8i and older Oracle databases did not support SQL TIMESTAMP, however Oracle
DATE contains a time component, which is an extension to the SQL standard. In
order to correctly handle the time component of Oracle DATE the 8i and
earlier drivers mapped Oracle DATE to java.sql.Timestamp. This preserved the
time component.
Oracle database 9.0.1 included support for SQL TIMESTAMP. In the process of
implementing support for SQL TIMESTAMP we changed the 9i JDBC driver to map
Oracle DATE to java.sql.Date. This was an incorrect decision since it
truncates the time component of Oracle DATE. There was also a backwards
compatibility problem trying to write java.sql.Timestamps to 8i databases.
These are separate problems but we "fixed" both under the control of a single
flag, V8Compatible. This flag was introduced in a 9.2 patch set.
By default the flag is false. When it is set to false the driver maps Oracle
DATE to java.sql.Date, losing the time component and it writes
java.sql.Timestamps to the database as SQL TIMESTAMPS. When the flag is set
to true the driver maps Oracle DATE to java.sql.Timestamp and writes
java.sql.Timestamps to the database as Oracle DATEs.
In 11.1 the V8Compatible flag was deprecated because it controlled Database
8i compatibility which is no longer supported. The additional behavior it
controlled, how SQL DATEs are handled, is controlled by a new flag,
mapDateToTimestamp. In 11.1 setting V8Compatible will just set
mapDateToTimestamp. This new flag only controls how SQL DATEs are
represented, nothing more. This flag will be supported for the foreseeable
future.
Finally, the default value for V8Compatible is false in 9i and 10g. This
means that by default the drivers incorrectly map SQL DATEs to java.sql.Date.
In 11.1 the default value of mapDateToTimestamp is true which means that by
default the drivers will correctly map SQL DATEs to java.sql.Timestamp
retaining the time information. Any customer that is currently setting
V8Compatible = true in order to get the DATE to Timestamp mapping will get
that behavior by default in 11.1. Any customer that wants the incorrect but
10g compatible DATE to java.sql.Date mapping can get that by setting
mapDateToTimestamp = false in 11.1.
About the only way to see the difference between mapDateToTimestamp settings
is to call getObject on a DATE column. If mapDateToTimestamp is true, the
default setting, the result will be a java.sql.Timestamp. If
mapDateToTimestamp is false, then getObject on a DATE column will return a
java.sql.Date.
HTH
Edited by: vasan_kps on Jun 12, 2009 2:01 PM
Maybe you are looking for
-
VirtualBox: Problems installing NW2004s ABAP Trial Version on Win XP Pro
Hi I'm at Mac OS X user who have installed a Win XP Pro SP2 guest OS in VirtualBox. - I made a NTFS format on the virtual disk (40GB). - 2GB RAM is assigned to the Win XP Pro guest OS - Java JRE 1.4.2_17 has been installed When I installed NW2004s AB
-
Why can't I drag things to the timeline?
I decided to upgrade to Adobe Premiere Pro CS3 last night after long debate and not wanting to spend the money. Everything is going pretty well now after transferring my project created using Adobe Premiere Elements 3.0 into the new program. But now
-
Hi Friends, I have created gr,and captured and posted the excise values.now my query is 1. While desplaying the materal document, excise details, i am not getting. 2. for sec & hsec cess, the values are not flowing to part2 ce
-
Displaying image in crystal reports
I am storing the logo of my customer in the database(SQL Server 2005) in binary format.I use VS2005 for developing my application.I would like to use the logo from the database in all the crystal reports(which are already connected to concerned store
-
Flash Lite - Automatic playback of SWF-files within MMS
Dear flash communty, I've the problem that SWF-files doesn't play automatically when I open the MMS I received. I tried to solve the problem with SMIL files, but it seams that the Flash Lite player doesn't support these scripts. Does anyone of you