About ResultSet.getDate
when I insert the table ,I use the to_date function to insert the date value,such as to_date('2003-05-24 14:00:00','yyyy-mm-dd hh24;mi:ss')
when using the Result.getDate,the return value of date is "2003-05-24",how can I get the correct value ?
thks very much!!!!!!!!!!!!!!!
try getTimestamp() instead.
Similar Messages
-
Assigning ResultSet.getDate()
(Posted this query to Programming forum by mistake earlier, so copying it to this forum. Apologies, I'm a newbie here...)
I am using ResultSet.getDate() to get a date field from MSSQL Server database. What variable type do I best assign the returned value to? getDate() returns a java.sql.Date object. I need to adjest date to account for time zone differences then return adjusted date to dbase.
Have tried
java.sql.Date cDate = rs.getDate("CDateTime");
CDateTime is the name of the field in dbase, but I get an
error thrown at this line as:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
My select statement is:
String sql = "SELECT * FROM \"CallRecd\"";
ResultSet rs = stmt.executeQuery(sql);
Would appreciate any comments on best way to assign rs.getDate().
Any comments on why this error is thrown? I have double checked that column name used is correct.Hi tully4,
What order are you trying to access your resultset fields? Apparently M$ SQL Server 7 doesn't like out of order access to resultset columns. If you access your resultset columns in ascending order everything is ok, but if you access a lower index column after a higher one.....
BTW you should really specify each column you want to select rather than using SELECT *. You'll also know the order of your columns.
Also, try using rs.getTimestamp(int colIndex, java.util.Calendar cal) instead of rs.getDate to get your date. You can use the calendar param to set the time zone (if you don't specify a time zone the default for your JVM is used).
Richard -
Does anyone can tell me how to use ResultSet.getDate(String field, Calendar cal)method,, I have tried many way,,, but if I use this method, everytime throw a AbstractMethodError... thanks
Calendar calendar = Calendar.getInstance();
while(rs.next){
rs.getDate("SYSDATE", calendar);
and SYSDATE is a kind of DATE
java.lang.AbstractMethodError occur while I run
rs.getDate() Method ..
is this a bug of java???It may simply be that the driver you are using doesn't support this method. Which driver and version are you using?
Col -
Bug in ResultSet#getDate() with ojdbc7-12.1.0.1
As "documented" here java - ResultSet#getDate() semantics - Stack Overflow there seems to be a bug in ResultSet#getDate() with ojdbc7-12.1.0.1.
The java.sql.Date condition
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero
is violated.
How can we report that to Oracle?Hello Hwang
1/ I don't know for your first question. Have you checked all the RUEI rpm prerequisites? One should be missing probably.
2/ One solutions consists of installing and configuring Squid proxy on the RUEI server. Then you can use your own browser with ruei server as a proxy and surf. You also need to tweak RUEI to collect traffic within the right network card.
as $RUEI_USER :
execsql config_set_profile_value wg profile_wg_localhost_1 config ForceInterface add eth0
replace wg by the name of your profle (probably wg anyay) and eth0 by the proper network card (also eth0 probably).
GL & HF
JB -
Why ResultSet getDate() method returns null when querying .csv file?
Here is the full code:
import java.sql.*;
import java.sql.Types;
import java.sql.Date;
import myjava.support.CachedRowSetMaker;
import javax.sql.rowset.CachedRowSet;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
class jdbc2{
final private String s1="SELECT top 10 [DATE], [ADJ CLOSE] FROM [vwo-1.csv]";
private ResultSet result=null;
private Connection conn=null;
public static void main(String[] args) throws SQLException{
jdbc2 db=new jdbc2();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
db.conn = DriverManager.getConnection("jdbc:odbc:STOCK_DATA");
PreparedStatement sql=db.conn.prepareStatement(db.s1);
db.result=sql.executeQuery();
// check column names and types using the ResultSetMetaData object.
ResultSetMetaData metaData = db.result.getMetaData();
System.out.println("Table Name : " + metaData.getTableName(2));
System.out.println("Field\t\tDataType");
for (int i = 0; i < metaData.getColumnCount(); i++) {
System.out.print(metaData.getColumnName(i + 1) + "\t");
System.out.println(metaData.getColumnTypeName(i+1));
System.out.print(metaData.getColumnName(1) + "\t"+metaData.getColumnName(2)+"\n");
while (db.result.next()){
System.out.print(db.result.getDate("DATE", Calendar.getInstance()));
System.out.format("\t%,.2f\n", db.result.getFloat("Adj Close"));
catch (Exception e) {
System.out.println("Error: " + e.getMessage());
finally {
db.result.close();
db.conn.close();
Everything works well, until getting to the block
while (db.result.next()){
System.out.print(db.result.getDate("DATE", Calendar.getInstance()));
System.out.format("\t%,.2f\n", db.result.getFloat("Adj Close"));
The getDate("DATE", Calendar.getInstance())); always returns null, instead of the date value in the vwo-1.csv.
Even though I change it to
java.sql.Date d=db.result.getDate("DATE") and convert to String using .toString(), I still gets nulls. The dollar amount in "Adj Close" field is fine, no problem.
The .csv fils is downloaded from YahooFinace.
Can anyone review the code and shed some light as to what I did wrong?
Thanks alot.CREATE TABLE `login` (
`username` varchar(40) DEFAULT NULL,
`password` varchar(40) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `amount` (
`amountid` int(11) NOT NULL,
`receiptid` int(11) DEFAULT NULL,
`loanid` int(11) DEFAULT NULL,
`amount` bigint(11) DEFAULT NULL,
`latefee` int(11) DEFAULT NULL,
`paymentid` int(11) DEFAULT NULL,
`pid` int(11) DEFAULT NULL,
PRIMARY KEY (`amountid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `applicationfee` (
`applicationfeeid` int(11) DEFAULT NULL,
`applicationamount` int(11) DEFAULT NULL,
`applicationfee` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `category` (
`categoryid` int(11) DEFAULT NULL,
`categoryname` varchar(40) DEFAULT NULL,
`categorydescription` varchar(500) DEFAULT NULL,
`cattype` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `commission` (
`commissionid` int(11) DEFAULT NULL,
`bussiness` int(11) DEFAULT NULL,
`commission` int(11) DEFAULT NULL,
`pid` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `customer` (
`cacno` int(11) NOT NULL DEFAULT '0',
`name` varchar(40) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`cphone` varchar(40) DEFAULT NULL,
`cmobile` varchar(40) DEFAULT NULL,
`caddress` varchar(500) DEFAULT NULL,
`cstatus` varchar(20) DEFAULT NULL,
`cphoto` longblob,
`pid` int(11) DEFAULT NULL,
PRIMARY KEY (`cacno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `daybook` (
`closingbal` varchar(40) DEFAULT NULL,
`date` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `extraincome` (
`categoryid` int(11) NOT NULL,
`receiptid` int(11) DEFAULT NULL,
`date` date DEFAULT NULL,
`amountid` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `employee` (
`empno` int(11) DEFAULT NULL,
`empname` varchar(40) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`sal` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `image` (
`id` int(11) DEFAULT NULL,
`image` blob
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `loan` (
`loanid` int(11) NOT NULL DEFAULT '0',
`loanamt` varchar(40) DEFAULT NULL,
`payableamount` double DEFAULT NULL,
`installment` int(11) DEFAULT NULL,
`payableinstallments` int(11) DEFAULT NULL,
`monthlyinstallment` varchar(20) DEFAULT NULL,
`surityname` varchar(20) DEFAULT NULL,
`applicationfeeid` int(11) DEFAULT NULL,
`interestrate` float DEFAULT NULL,
`issuedate` date DEFAULT NULL,
`duedate` date DEFAULT NULL,
`nextduedate` date DEFAULT NULL,
`cacno` int(11) DEFAULT NULL,
`cname` varchar(20) DEFAULT NULL,
`pid` int(11) DEFAULT NULL,
`interestamt` double DEFAULT NULL,
`pendingamt` float DEFAULT NULL,
PRIMARY KEY (`loanid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `md` (
`mdid` int(11) NOT NULL DEFAULT '0',
`mdname` varchar(40) DEFAULT NULL,
`mdphoto` varchar(100) DEFAULT NULL,
`mdphone` varchar(40) DEFAULT NULL,
`mdmobile` varchar(40) DEFAULT NULL,
`mdaddress` varchar(500) DEFAULT NULL,
PRIMARY KEY (`mdid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `partner` (
`pid` int(11) NOT NULL DEFAULT '0',
`pname` varchar(40) DEFAULT NULL,
`paddress` varchar(500) DEFAULT NULL,
`pphoto` varchar(100) DEFAULT NULL,
`pphone` varchar(40) DEFAULT NULL,
`pmobile` varchar(40) DEFAULT NULL,
`pstatus` varchar(20) DEFAULT NULL,
`mdid` int(11) DEFAULT NULL,
`mdname` varchar(40) DEFAULT NULL,
`date` date DEFAULT NULL,
`nextpaydate` date DEFAULT NULL,
PRIMARY KEY (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `partnerinvested` (
`pid` int(11) DEFAULT NULL,
`pname` varchar(20) DEFAULT NULL,
`receiptid` int(11) DEFAULT NULL,
`date` date DEFAULT NULL,
`amountinvested` int(11) DEFAULT NULL,
`latefee` int(11) DEFAULT NULL,
`amountid` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `payments` (
`paymentid` int(11) NOT NULL,
`categoryid` int(11) DEFAULT NULL,
`particulars` varchar(100) DEFAULT NULL,
`amountid` int(11) DEFAULT NULL,
`paymentdate` date DEFAULT NULL,
PRIMARY KEY (`paymentid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `receipts` (
`receiptid` int(11) DEFAULT NULL,
`paiddate` date DEFAULT NULL,
`amountid` int(11) DEFAULT NULL,
`loanid` int(11) DEFAULT NULL,
`latefee` int(11) DEFAULT NULL,
`installment` int(11) DEFAULT NULL,
`cacno` int(11) DEFAULT NULL,
`cname` varchar(40) DEFAULT NULL,
`pid` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1; -
A question about ResultSet.UpdateObject(int column, Object x)
hi, I write some code which use the TableModel to represent the data fetched from MS-ACCESS.
the problem is about the UpdateObject(...) method which is in the implement of the AbstractTableModel method setAtValue(). when transfered OBJECT TYPE is java.lang.String, I can't get the correct result in the JTable view.
my code is as below, could somebody point me out my problem
public class MyTableModel extends AbstractTableModel {
private ResultSet rs ;
private ResultSetMetaData rsmd;
/** Creates a new instance of MyTableModel */
public MyTableModel() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
String url = "jdbc:odbc:CoffeeBreak";
try {
Connection con = DriverManager.getConnection(url,"","");
String strSQL = "SELECT * FROM COFFEES";
Statement pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pSt.executeQuery(strSQL);
rsmd = rs.getMetaData();
} catch (SQLException ex) {
ex.printStackTrace();
/* table model retrieve the Class type of a column method here*/
public Class getColumnClass(int c){
try {
return Class.forName(rsmd.getColumnClassName(c+1));
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
return String.class;
//method of update database and JTable after user edited a table cell
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
int concurrency = rs.getConcurrency();
if(concurrency == 1008){
rs.absolute(rowIndex+1); //the JTable row index is start from 0,so plus 1
rs.updateObject(columnIndex+1, aValue);//the JTable column index is start from 0, so plus 1
rs.updateRow();
} catch (SQLException ex) {
ex.printStackTrace();
}when the column type is about java.lang.String, the cell's result is incorrect, it looks like "[B@1f8f72f" and database can't update.It's me again.
I post the whole class code here
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
* @author qhj
public class MyTableModel extends AbstractTableModel {
/** Creates a new instance of MyTableModel */
private ResultSet rs ;
private ResultSetMetaData rsmd;
private Statement pSt;
private String strSQL;
public MyTableModel() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
String url = "jdbc:odbc:CoffeeBreak";
try {
Connection con = DriverManager.getConnection(url,"","");
strSQL = "SELECT * FROM COFFEES";
pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = pSt.executeQuery(strSQL);
rsmd = rs.getMetaData();
} catch (SQLException ex) {
ex.printStackTrace();
public int getRowCount() {
try {
rs.last();
return rs.getRow();
} catch (SQLException ex) {
ex.printStackTrace();
return 0;
public int getColumnCount() {
try {
return rsmd.getColumnCount();
} catch (SQLException ex) {
ex.printStackTrace();
return 0;
public Object getValueAt(int rowIndex, int columnIndex) {
try {
rs.absolute(rowIndex+1);
return rs.getObject(columnIndex+1);
} catch (SQLException ex) {
ex.printStackTrace();
return null;
public String getColumnName(int column){
try {
return rsmd.getColumnName(column+1);
} catch (SQLException ex) {
ex.printStackTrace();
return "N/A";
public Class getColumnClass(int c){
try {
return Class.forName(rsmd.getColumnClassName(c+1));
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
return String.class;
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
return true;
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
int concurrency = rs.getConcurrency();
if(concurrency == 1008){
rs.absolute(rowIndex+1);
rs.updateObject(columnIndex+1, aValue);
//rs.updateRow();
//rs = pSt.executeQuery(strSQL);
} catch (SQLException ex) {
ex.printStackTrace();
fireTableDataChanged();
} -
Resultset.getDate() truncation
when i call getDate() from the resultset to receive the full date, . i get a truncated, date back, minus the time part.
i can use, getTimestamp() to retrieve the full date, . but then what is the easiest way to convert java.sql.timestamp to a normal date object for manip?java.sql.timestamp is a thin wrapper around java.util.Date that allows JDBC to identify this as a SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP nanos value and provides formatting and parsing operations to support the JDBC escape syntax for timestamp values.
Note: This type is a composite of a java.util.Date and a separate nanos value. Only integral seconds are stored in the java.util.Date component. The fractional seconds - the nanos - are separate. The getTime method will return only integral seconds. If a time value that
includes the fractional seconds is desired, you must convert nanos to milliseconds
(nanos/1000000) and add this to the getTime value.
(above from Java Documentation)
I use:
java util.date dateField;
dateField=rset.getTimestamp("DATE_FIELD");
String s = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(dateField);
And the date and time are returned without using java.sql.timestamp. I don't need more than seconds precision. -
Hi,
I have a simple problem. I wish to move data from a resultset to a string[]. However, I do not know the number of rows in the resultset.
I have tried something like this:
while (resultset.next()) {
while ( (sqlData[rowCount++] = resultset.getString(++colCount))){}
colCount = 0;
}Javac said it expected a boolean and not a string. Well of course it requiers a boolean, but isn't a boolean returned if the operation on the resultset isn't possible?
All help appriciated...
Karl XIIIt is possible to retrieve the number of rows from a resultset --
Statement stmt= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READONLY);
ResultSet rs= stmt.executeQuery("<your select query here>");
int totalRows;
if (rs.last()) // can it move to the last row?
totalRows= rs.getRow(); // get its row number
else
totalRows= 0; // no rows in the resultset
rs.first() // set the cursor back to the startNote that the resultset has to be scrollable (TYPE_SCROLL_INSENSITIVE).
kind regards,
Jos -
Question about ResultSet Columns
Do resultset columns start at index 0 or 1???
From the [url http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html]API docs
The ResultSet interface provides getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once. -
i want to transfer the resulset to a different array.how can i do that.shall i use vector or arraylist.or is there an easier way.could you give me sample codes.
Iterate through the ResultSet, create objects representing the rows, and add those objects to a Collection of your choice. ArrayList is the most common general-purpose collection.
-
Q1. Do I need to ( Or should I for good programming practice ) explicitly close a ResultSet ?
Q2. Does a ResultSet contain retrieved records from the query or a list of "pointers" to records which are retrieved from the DB only as the ResultSet is walked through?
Thanks ..... JQ1. Do I need to ( Or should I for good programming
practice ) explicitly close a ResultSet ?You should, and sometimes you need to, e.g. to avoid getting a "too many open cursors" database error when using lots of ResultSets within a short span of time.
Q2. Does a ResultSet contain retrieved records from
the query or a list of "pointers" to records which
are retrieved from the DB only as the ResultSet is
walked through?Depends on the implementation. Typically, it does contain some (if not all) records. Other data (e.g. BLOBs) might be read in streaming mode. -
Question about buffer, getData()?
Hello,
Could anyone advise, I wrote a program to loop through the frames of a color .avi video. As I understand its possible to access the buffers pixels using getData();
positioner.seek(i);
buffer = grabber.grabFrame();
But I wondered if the the getData would return the pixels in a RGB format, or if the format could other color types?
ThanksYou'll want to look through that sample code and pay special attention to where they specify the supported Formats of the data.
http://java.sun.com/products/java-media/jmf/2.1.1/apidocs/javax/media/Format.html
Given a byte array and a RGBFormat object, do you think you could figure out how to extract the individual pixels? -
Using getDate for ResultSet in jsp
Hello,
In a jsp I'm trying to display a date stored in a mysql database.
In the jsp i have put the following:
<TD align='right'>Meeting Date</TD>
<TD align='right'>
<INPUT type='text' name='meetingDate' value='<%= rsClients.getDate("meetingDate") %>'</TD>
</TR>
rsClients is the ResultSet where I have stored mysql table data.
But when I run servlet that subsequently fires up jsp to display data stored in mysql database I get the following sql exception:
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
at com.mysql.jdbc.ResultSet.getDateFromString(ResultSet.java:1913)
at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1849)
at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1817)
at com.mysql.jdbc.ResultSet.getDate(ResultSet.java:1865)
at org.apache.jsp.ProcessClients$jsp._jspService(ProcessClients$jsp.java:154)
Can anyone explain why I'm getting this error please,
Cheers Joe.I think you have store wrong data in Date Type field in MYsql
so try to store data in formate of YYYY-MM-DD right now it is 0000-00-00
Because you have try to enter any No,String or It isnot Correct date Type -
ResultSets Closing, cant use .last() etc
I am filling 3 seperate resultsets using 3 seperate sql queries.
The 1st query calls the connection classes setData() and passes in the sql statement, which connects, gets the data, puts it in a resultset, and returns it to the calling class. Then, the returned resultset copied into resultset1.
The 2nd query then does the same thing, but its sql statement is getting different data from a different table, but it still uses the getData() method to do it. It then fills resultset2.
Then the 3rd query runs its sql query the same way to fill resultset3.
The problem is, after i have filled resultsets 1, 2 and 3, it wont let me call a .first() or .last() on any of them cause it says that the resultset is closed! Heres the exact error msg:
"java.sql.SQLException: Operation not allowed after ResultSet closed"
Heres the code where i try fill the 3 resultsets:
mycon = new MysqlConnect();
details_res = mycon.getData("SELECT * FROM details ORDER BY details_id");
details_res.last();
parts_res = mycon.getData("SELECT * FROM parts ORDER BY parts_id");
parts_res.last();
costs_res = mycon.getData("SELECT * FROM costs ORDER BY costs_id");
costs_res.last();'mycon' is an object of the connection class.
So im guessing that ive got a problem in the getData() method of the connection class so heres the code for that method:
public ResultSet getData(String query)
connect();
try
// browseable in all directions, not sensitive to updates by other users, not updateable
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // create empty SQL statement
// execute SQL query & store results
result = stmt.executeQuery(query);
con.close(); // close connection
System.out.println("Data Retrieved. Connection Closed");
catch (SQLException e)
System.out.println("SQL Exception " + e);
return result; // return the data
}//end getData()'stmt' and 'con' are both declared at the top, private variables.Right. Exactly. This is the way it's supposed to be. You've got major fundamental flaws in your approach.
First, the result set is not being copied, you're creating a new reference to it.
Second, result sets AREN'T copied.
Third, a ResultSet represents an arbitrarily large flow of data that will come throw the connection as you step through elements in the ResultSet; as soon as you close the connection, you cut off the flow.
So the excpetion is exactly right, you've closed the flow and therefore can't move around in the ResultSet. -
Help: ResulSet.getDate(int col) rounds time to 12:00AM
Using Microsoft SQL Server 7, I execute the following code:
CREATE TABLE Test (RegDate DATETIME, SmallDate SMALLDATETIME)
INSERT INTO Test (RegDate, SmallDate) VALUES ('1/1/2000 5:37 AM', '1/1/2000 5:37 AM')
SELECT * FROM TestThis is the output that I get back:RegDate SmallDate
2000-01-01 05:37:00.000 2000-01-01 05:37:00Ok, it looks good so far... now let me query this table with JDBC://just a snippet... I already have a connection, and a statement (stmt)
SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy h:mm:ss a");
ResultSet rs = stmt.executeQuery("SELECT * FROM Test");
while(rs.next()) {
System.out.println("RegDate is " + format.format(rs.getDate(1)));
System.out.println("SmallDate is " + format.format(rs.getDate(2)));
}The output from the java code is:RegDate is 1/1/2000 12:00 AM
SmallDate is 1/1/2000 12:00 AMThe month, day and year are correct but the hours and minutes are 12:00 AM. How can I get the hours and minutes?
Thanks,
jayOkay, I did some reading and I learned that java.sql.Date will always show 12:00 AM (aka zero). There is a class called java.sql.Time which should take care of the time.
I still don't know how to get the Date and time from a ResultSet though. I can call ResultSet.getDate(int col) or ResultSet.getTime(int col) but not both (after getting a column's value, subsequent calls return null). I even tried getting raw data and parsing it via ResultSet.getBytes() and ResutSet.getBinaryStream()... common sense tells me that there's got to be a cleaner, simpler way to do this. Surely I'm not the first person who wanted to read the date and time from a SQLServer DATETIME column!
thanks again
Maybe you are looking for
-
My iPhone 5 is not recognized by computer
I just recieved my new iPhone 5 yesterday in the mail and when I plug it in to my computer (Window XP) it doesnt even recognize it. It just make 3 beeps and I dont know why? I just want to sync my music and videos to my new phone.
-
Error while installing Device Software Update usin...
I have installed Nokia Suite 3.2.100 on my Win XP-SP3 machine. Upon signing in, Nokia Suite indicated that I have an update available for my device (Nokia N8-00 running Symbian Anna, Type RM-596). The application available for update was Nokia Maps -
-
I have made an IMovie consisting of slides and some video. I cannot create a DVD with it. A window tells me there is a problem and that the problem is listed in the User parameters.....I am at a loss. There are hours of work in the Movie. Anyone
-
VPN hub and spoke topology, hub using two interfaces
Hi, I'm facing a problem with Cisco ASA 5500 running software 8.4. I know, i know, VPN hub and spoke was already discussed many times. But all these discussions are about a hub using only one interface, the outside/public interfcae. My topology is sl
-
Ipad3 - trying to upgrade to ios7 - can't upgrade - in a recovery loop
Hi, I have iPad 3 that I was trying to upgrade to iOS 7. In the midst of upgrading iPad3 to iOS7, iOS7 upgrade encountered unknown error and aborted the upgrade. Now my iPad3 is in recovery mode loop. Every time, it asks me to recover but it fails wi