Hi,
I have the following static method in a class to read out the actual date (=
database sysdate, not the date configured in the client machine or on the
server):
package pt.hostdat.hcc.uci.database.sonho;
import static pt.hostdat.hcc.uci.database.sonho.IConstants.JNDI;
import static pt.hostdat.hcc.uci.database.sonho.IConstants.PROP;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import pt.hostdat.hcc.common.database.DAOException;
import pt.hostdat.hcc.common.database.DatabaseConnectionProvider;
import pt.hostdat.hcc.common.util.Util;
/**
* Utility class to read out SYSDATE.
*
* @author Alberto Smulders
*/
public class DataSistema implements Serializable {
public static Date getDate() {
Date sysdate = null;
Connection conn = null;
try {
String sql = " select trunc(SYSDATE) TODAY from DUAL";
DatabaseConnectionProvider connProvider =
new DatabaseConnectionProvider(JNDI, PROP);
conn = connProvider.getConnection();
conn.setAutoCommit(false);
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
if (resultSet.next()) {
sysdate = resultSet.getDate("TODAY");
System.out.println(sysdate);
}
resultSet.close();
statement.close();
conn.close();
}
catch (DAOException e) {
Util.showFatalErrorMsg("Erro fatal: " + e.getMessage());
}
catch (SQLException e) {
Util.showFatalErrorMsg("Erro fatal: " + e.getMessage());
}
finally {
if (conn != null) {
try {
conn.close();
}
catch (SQLException ex) {
}
}
}
return sysdate;
}
}
I use the class in a form:
public void initialize() {
// ... other code ...
fDate.setValue(DataSistema.getDate());
}
And I get the following result:
2006-06-19
1 19.06.2006 12:50:23.843 1.000 SEVERE Thread[ULC
Communication Controller Thread,6,main]
com.ulcjava.base.client.UISession$k_ run exception occured
[com.ulcjava.base.client.ConnectorException: error while sending requests
at
com.ulcjava.base.development.DevelopmentConnector.sendRequests(DevelopmentConnector.java:33)
at com.ulcjava.base.client.UISession$k_.run(UISession$k_.java:19)
at java.lang.Thread.run(Unknown Source)
Caused by: com.ulcjava.base.shared.internal.IllegalArgumentException: No coder
registered for class java.sql.Date
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.a(UlcObjectOutputStream.java:131)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:104)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:39)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:39)
at
com.ulcjava.base.shared.streamcoder.CollectionCoder.writeObject(CollectionCoder.java:5)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:31)
at
com.ulcjava.base.shared.streamcoder.MapCoder.writeObject(MapCoder.java:18)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:31)
at
com.ulcjava.base.shared.streamcoder.AnythingCoder.writeObject(AnythingCoder.java:5)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:31)
at
com.ulcjava.base.shared.streamcoder.MapCoder.writeObject(MapCoder.java:18)
at
com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(UlcObjectOutputStream.java:31)
at
com.ulcjava.base.shared.internal.Request.writeRequests(Request.java:2)
at
com.ulcjava.base.development.DevelopmentConnector.a(DevelopmentConnector.java:36)
at
com.ulcjava.base.development.DevelopmentConnector.sendRequests(DevelopmentConnector.java:32)
at com.ulcjava.base.client.UISession$k_.run(UISession$k_.java:19)
at java.lang.Thread.run(Unknown Source)
]
As you can see, the sysdate value is correctly retrieved from the (Oracle)
database...
Some hints what might be wrong?
Kind regards,
Alberto A.Smulders
HostDat Lda. - Portugal
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer