(URGENT)Problem using WebSphere 4.0.2 datasource inserting record to DB2 in AS400 V4R5
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   stanley_ten
Posted On:   Thursday, July 18, 2002 08:53 PM

By using the codes below, i try to insert 2 dates into database, but when i check the table, the field DATE1(ISO), DATE2(ISO) is blank... how to solve this problem? // Get datasource using JNDI String providerURL = "iiop:///"; // Obtain an initial context Hashtable parms = new Hashtable(); // Context factory for Websphere 4 parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); parms.put(Context.PROVIDER_URL, providerURL); InitialContext context = new InitialContext(parms); if (context == null) System.out.print("Context is null");    More>>

By using the codes below, i try to insert 2 dates into database, but when i check the table, the field DATE1(ISO), DATE2(ISO) is blank...
how to solve this problem?

// Get datasource using JNDI

String providerURL = "iiop:///";

// Obtain an initial context

Hashtable parms = new Hashtable();

// Context factory for Websphere 4

parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

parms.put(Context.PROVIDER_URL, providerURL);

InitialContext context = new InitialContext(parms);

if (context == null) System.out.print("Context is null");

DataSource ds = (DataSource) context.lookup("jdbc/bosdb");

if (ds == null) System.out.print("TestDB400Write : DataSource is null");

conn = ds.getConnection();

conn.setAutoCommit(false);

stmt = conn.prepareStatement("INSERT INTO TESTTABLE (KEY1, DATE1, DATE2) VALUES(?,?,?)");

stmt.clearParameters();

stmt.setString(1,"D");

stmt.setDate(2,returnDate("2060-01-01"));

stmt.setDate(3,returnDate("1930-01-01"));

test = stmt.executeUpdate();

if (test == 1) {

conn.commit();

}




public static java.sql.Date returnDate(String formDate) {

java.sql.Date sqlDate = null;

try {

// if formDate format is dd/mm/yyyy, convert it to yyyy-mm-dd

SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy");

SimpleDateFormat df2 = new SimpleDateFormat("yyyy/MM/dd");

if (formDate.indexOf("/") > 0) {

df2.format(df1.parse(formDate));

formDate = df2.format(df1.parse(formDate)).replace('/', '-');

}

sqlDate = java.sql.Date.valueOf(formDate);

} catch (ParseException pxp) {}

catch (Exception e) {}

return sqlDate;

   <<Less
About | Sitemap | Contact