Re: java.lang.NullPointerException while updating datetime field
- From: "joeNOSPAM@xxxxxxx" <joe.weinstein@xxxxxxxxx>
- Date: 9 Oct 2006 13:59:46 -0700
On Oct 9, 1:09 pm, "suhartha" <suhar...@xxxxxxxxx> wrote:
Hi,
I am banging my heads for last several days with this issue. I am
trying to update a field which is a datetime field in a table in the
ORACLE database. I am using JAVA1.5 and JDBC:ODBC driver for making the
bridge. After i run the following prog i get the
"java.lang.NullPointerException
" error. I found that it crashes so just after executing
rs2.updateRow() statement.
I found lots of suggestions from the previos posts but none helped me.
If any of you can tell me what is the problem or how to fix it I will
be grateful.
======================================================================
public static void main( String [] args ) {
Connection c1 = null;
Connection c2 = null;
Statement stmt1 = null;
Statement stmt2 = null;
// use the following variables to store data from Rate_General
table
int media_num;
// use the following variables to store data from the .XLS file
int media_num_xl;
Calendar c = Calendar.getInstance();
c.set(2001,1,1);
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); // Create
the driver for making the bridge
c1 = DriverManager.getConnection( "jdbc:odbc:ExpireOnlysc",
"", "" ); // connect to .XLS file
c2 = DriverManager.getConnection( "jdbc:odbc:benchmark",
"chowdhurys", "Blackvax1" ); //connect to benchmark Database
if (args.length == 0) {
ResultSet rs1, rs2;
stmt1 =
c1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt2 =
c2.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs1 = stmt1.executeQuery( "select PRODUCT_LINE_TC,
MEDIA_NUM, EDITION_TC, RATE_STRUCTURE_TC, RATE_EFF_DATE, CONFIRM_DATE,
SOURCE
from
[ExpireOnlysc$]" );
rs2 = stmt2.executeQuery( "select PRODUCT_LINE_TC,
MEDIA_NUM, EDITION_TC, RATE_STRUCTURE_TC, RATE_EFF_DATE, CONFIRM_DATE,
SOURCE, RATE_EXP_DATE from
RATE_GENERAL where PRODUCT_LINE_TC LIKE 'INSERT' and RATE_STRUCTURE_TC
LIKE 'FOODSERV'" );
rs1.next();
int i = 1;
while( rs2.next())
{
if (rs2.getRow() == 25) //Testing with 10 records
initially
break;
media_num = rs2.getInt("MEDIA_NUM");
media_num_xl = rs1.getInt("MEDIA_NUM");
if ( media_num == media_num_xl)
{
Long time= c.getTimeInMillis();
Date d = new Date(time);
java.sql.Timestamp sqlDate = new
java.sql.Timestamp( d.getTime() );
//
returns the number of Millisec for this Date object
rs2.updateTimestamp("RATE_EXP_DATE", sqlDate);
//==========THIS IS WHERE IT
CRASHES============
rs2.updateRow();
i++;
}
rs1.absolute(i); // reposition the cursor in the
.xls file
}
System.out.println("TOTAL: " + i );
rs1.close();
rs2.close();
}
} catch( Exception e ) {
System.err.println( e );
} finally {
try {
stmt1.close();
c1.commit();
c1.close();
stmt2.close();
c2.commit();
c2.close();
} catch( Exception e ) {
System.err.println( e );
}
}
} // end of main
} // end of ExcelReaderWriter classRegards,
Suhartha Chowdhury
Valassis INC
The first thing is to drop all further use
of the JDBC-ODBC bridge. Use Oracle's
thin driver for real supportable JDBC,
and let us know if it works or not...
Joe Weinstein at BEA Systems
.
- Follow-Ups:
- References:
- java.lang.NullPointerException while updating datetime field
- From: suhartha
- java.lang.NullPointerException while updating datetime field
- Prev by Date: java.lang.NullPointerException while updating datetime field
- Next by Date: Re: java.lang.NullPointerException while updating datetime field
- Previous by thread: java.lang.NullPointerException while updating datetime field
- Next by thread: Re: java.lang.NullPointerException while updating datetime field
- Index(es):
Relevant Pages
|
|