Advertisement

09.15.2005 at 08:15AM PDT, ID: 21562688
[x]
Attachment Details

Problem with DB2 Timestamp Insert Statement

Asked by ngujja in Java Programming Language

Tags: db2, timestamp, insert

Hi,
I want to insert a simple record in the DB2, programmatically. Here's the code which does it.

java.util.Calendar cal = new java.util.GregorianCalendar();
                  java.util.Date now = cal.getTime();
                  long t = now.getTime();
                  java.sql.Date date = new java.sql.Date(t);//2005-01-01.12.13.02.030000
                  java.sql.Timestamp ts = new java.sql.Timestamp(t);
                  
                  connection = LLBJdbcConnection.getJDBCConnection(LLBJdbcConnection.STANDARD);
                  stmt = connection.createStatement();
                  query = "INSERT INTO auth_temp_stats VALUES ("+date+",' ',' ',' ',' ',' ',' ',' ',0,' ',' ',"+ts+")"; <-- notice ts
                  ret = stmt.executeUpdate(query);

Here's the error message.

    [junit] com.ibm.db2.jcc.b.SqlException: ILLEGAL SYMBOL "11". SOME SYMBOLS TH
AT MIGHT BE LEGAL ARE: ) ,
    [junit]     at com.ibm.db2.jcc.b.id.e(id.java:1640)
    [junit]     at com.ibm.db2.jcc.b.id.b(id.java:1197)
    [junit]     at com.ibm.db2.jcc.c.fb.i(fb.java:234)
    [junit]     at com.ibm.db2.jcc.c.fb.b(fb.java:50)
    [junit]     at com.ibm.db2.jcc.c.s.b(s.java:36)
    [junit]     at com.ibm.db2.jcc.c.wb.f(wb.java:141)
    [junit]     at com.ibm.db2.jcc.b.id.m(id.java:1194)
    [junit]     at com.ibm.db2.jcc.b.id.a(id.java:1922)
    [junit]     at com.ibm.db2.jcc.b.id.c(id.java:560)
    [junit]     at com.ibm.db2.jcc.b.id.executeUpdate(id.java:545)
    [junit]     at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeUpdate(WSJdb
cStatement.java:489)
    [junit]     at com.llbean.paymentauthorization.statistics.service.PmtAuthSta
teStatSvc.dbInsertion(PmtAuthStateStatSvc.java:139)
    [junit]     at com.llbean.paymentauthorization.statistics.session.PmtAuthSta
teStat.dbInsertion(PmtAuthStateStat.java:62)
    [junit]     at com.llbean.paymentauthorization.statistics.session.PmtAuthSta
teStatTest.testDBInsertion(PmtAuthStateStatTest.java:83)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:79)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:41)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:386)
    [junit]     at junit.framework.TestCase.runTest(TestCase.java:154)
    [junit]     at junit.framework.TestCase.runBare(TestCase.java:127)
    [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run(TestCase.java:118)
    [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:208)
    [junit]     at junit.framework.TestSuite.run(TestSuite.java:203)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
run(JUnitTestRunner.java:297)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
launch(JUnitTestRunner.java:672)
    [junit] com.ibm.db2.jcc.b.SqlException: ILLEGAL SYMBOL "11". SOME SYMBOLS TH
AT MIGHT BE LEGAL ARE: ) ,
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
main(JUnitTestRunner.java:567)
    [junit] junit.framework.AssertionFailedError: expected:<1> but was:<-1>
    [junit]     at junit.framework.Assert.fail(Assert.java:47)
    [junit]     at junit.framework.Assert.failNotEquals(Assert.java:282)
    [junit]     at junit.framework.Assert.assertEquals(Assert.java:64)
    [junit]     at junit.framework.Assert.assertEquals(Assert.java:201)
    [junit]     at junit.framework.Assert.assertEquals(Assert.java:207)
    [junit]     at com.llbean.paymentauthorization.statistics.session.PmtAuthSta
teStatTest.testDBInsertion(PmtAuthStateStatTest.java:83)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:79)

I have also tried inserting timestamp format like 2005-10-14.10.30.15.610208 this also did not work.

What am i doing wrong.
ngujjaStart Free Trial
[+][-]09.15.2005 at 08:19AM PDT, ID: 14890070

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.15.2005 at 08:28AM PDT, ID: 14890179

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.15.2005 at 08:36AM PDT, ID: 14890267

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: db2, timestamp, insert
Sign Up Now!
Solution Provided By: zzynx
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.15.2005 at 08:52AM PDT, ID: 14890443

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.15.2005 at 11:51PM PDT, ID: 14895884

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32