Solved

COUNT field incorrect...

Posted on 2003-12-03
24
3,462 Views
Last Modified: 2007-12-19
spider is here. hope my java skill can like most of you, can run and no longer crawing.. ha...

this my code,
******
 
if (num!=0) {
try {
  ps2a = conn.prepareStatement("Update purchase SET (ExpDateA = ?,  Date = ?) WHERE Warranty = ? ");
  ps2b = conn.prepareStatement("Update purchase SET (ExpDateB = ?,  Date = ?) WHERE Warranty = ? ");
  ps2c = conn.prepareStatement("Update purchase SET (ExpDateC = ?,  Date = ?) WHERE Warranty = ? ");
  ps2d = conn.prepareStatement("Update purchase SET (ExpDateD = ?,  Date = ?) WHERE Warranty = ? ");
  ps2e = conn.prepareStatement("Update purchase SET (ExpDateE = ?,  Date = ?) WHERE Warranty = ? ");
  ps2f = conn.prepareStatement("Update purchase SET (ExpDateF = ?,  Date = ?) WHERE Warranty = ? ");

    for (int j=0;j<warranty.length;j++)
    {
      if(warranty[j].length() > 0) {
           if (filter[j].equals("A")) {
               ps.setString( 1, date[j]);  
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2a.executeUpdate()+number;
          }
          if (filter[j].equals("B")) {
               ps.setString( 1, date[j]);
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2b.executeUpdate()+number;
          }
           if (filter[j].equals("C")) {
               ps.setString( 1, date[j]);
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2c.executeUpdate()+number;
          }
           if (filter[j].equals("D")) {
               ps.setString( 1, date[j]);
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2d.executeUpdate()+number;
          }
           if (filter[j].equals("E")) {
               ps.setString( 1, date[j]);
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2e.executeUpdate()+number;
          }
           if (filter[j].equals("F")) {
               ps.setString( 1, date[j]);
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps.setString(3, warranty[j]);
               number=ps2f.executeUpdate()+number;
          }
       }
    }
.
.
.
..

but afer i execute it, it prompt me this error...

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
      at org.apache.jsp.tech_0005fconfirm$jsp._jspService(tech_0005fconfirm$jsp.java:165)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.netbeans.modules.

*****

I totally absolutely didn't use the COUNT statement on my program, not evene the above frst statement before this whole slack..

and i have count the "?" in my preparedstatement, how can i sovle this problem?

0
Comment
Question by:spiderman19
  • 14
  • 9
24 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9872363
>> at org.apache.jsp.tech_0005fconfirm$jsp._jspService(tech_0005fconfirm$jsp.java:165)
can you tell us error is from which line of code?
0
 

Author Comment

by:spiderman19
ID: 9872577
ken, tech_0005fconfirm$jsp.java:165) is referring to;

for (int j=0;j<warranty.length;j++)
    {
     if(warranty[j].length() > 0) {
          if (filter[j].equals("A")) {
              ps.setString( 1, date[j]);  
               ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
              ps.setString(3, warranty[j]);
>>>>>   number=ps2a.executeUpdate()+number;
         }
0
 
LVL 92

Expert Comment

by:objects
ID: 9872598
>    ps.setString( 1, date[j]);  
>    ps.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
>    ps.setString(3, warranty[j]);
>    number=ps2a.executeUpdate()+number;

You're setting the parameter values on ps, but executing ps2a.
0
 

Author Comment

by:spiderman19
ID: 9872628
object... so sorry....
tq
0
 

Author Comment

by:spiderman19
ID: 9872633
anything wrong with the rest of the code?
0
 
LVL 92

Expert Comment

by:objects
ID: 9872651
nothing obvious I can see. Is the problem still occurring after you set the statement parameters correctly?
0
 

Author Comment

by:spiderman19
ID: 9872687
yes, the update statement prompted me error pointing to this place...>>>                               number=ps2a.executeUpdate()+number;

.
.
.
 ps2a = conn.prepareStatement("Update purchase SET (ExpDateA = ?,  Date = ?) WHERE Warranty = ? ");
  ps2b = conn.prepareStatement("Update purchase SET (ExpDateB = ?,  Date = ?) WHERE Warranty = ? ");
  ps2c = conn.prepareStatement("Update purchase SET (ExpDateC = ?,  Date = ?) WHERE Warranty = ? ");
  ps2d = conn.prepareStatement("Update purchase SET (ExpDateD = ?,  Date = ?) WHERE Warranty = ? ");
  ps2e = conn.prepareStatement("Update purchase SET (ExpDateE = ?,  Date = ?) WHERE Warranty = ? ");
  ps2f = conn.prepareStatement("Update purchase SET (ExpDateF = ?,  Date = ?) WHERE Warranty = ? ");
.
.
.
    for (int j=0;j<warranty.length;j++)
                    {
                      if(warranty[j].length() > 0) {
                           if (filter[j].equals("A")) {
                               ps2a.setString( 1, date[j]);  
                               ps2a.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
                               ps2a.setString(3, warranty[j]);
>>>                               number=ps2a.executeUpdate()+number;
                          }

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
      at org.apache.jsp.tech_0005fconfirm$jsp._jspService(tech_0005fconfirm$jsp.java:158)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
0
 

Author Comment

by:spiderman19
ID: 9872694
i change to this :
ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ?,  Date = ? WHERE Warranty = ? ");
  ps2b = conn.prepareStatement("Update purchase SET ExpDateB = ?,  Date = ? WHERE Warranty = ? ");
  ps2c = conn.prepareStatement("Update purchase SET ExpDateC = ?,  Date = ? WHERE Warranty = ? ");
  ps2d = conn.prepareStatement("Update purchase SET ExpDateD = ?,  Date = ? WHERE Warranty = ? ");
  ps2e = conn.prepareStatement("Update purchase SET ExpDateE = ?,  Date = ? WHERE Warranty = ? ");
  ps2f = conn.prepareStatement("Update purchase SET ExpDateF = ?,  Date = ? WHERE Warranty = ? ");


also prompted me error.
0
 
LVL 92

Expert Comment

by:objects
ID: 9872695
different error :)
Your sql syntax looks incorrect, try getting rid of those brackets:

Update purchase SET ExpDateA = ?,  Date = ? WHERE Warranty = ? ");
0
 
LVL 92

Expert Comment

by:objects
ID: 9872699
> also prompted me error.

what error?
0
 

Author Comment

by:spiderman19
ID: 9872753
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
      at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
      at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
      at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
      at org.apache.jsp.tech_0005fconfirm$jsp._jspService(tech_0005fconfirm$jsp.java:158)
      at org.apache

pointing to

    if(warranty[j].length() > 0) {
                           if (filter[j].equals("A")) {
                               ps2a.setString( 1, date[j]);  
                               ps2a.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
                               ps2a.setString(3, warranty[j]);
>>>>>>>>             number=ps2a.executeUpdate()+number;
                          }

this is my preparedstatement.
 ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ?,  Date = ? WHERE Warranty = ? ");
  ps2b = conn.prepareStatement("Update purchase SET ExpDateB = ?,  Date = ? WHERE Warranty = ? ");
  ps2c = conn.prepareStatement("Update purchase SET ExpDateC = ?,  Date = ? WHERE Warranty = ? ");
 
0
 
LVL 92

Expert Comment

by:objects
ID: 9872785
whats your database schema?
having a field called Date may be a problem.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:spiderman19
ID: 9872829
?? you sure?

i have checked the inserting is no problem?
hm.. let me remove the date and let you know the result.
0
 

Author Comment

by:spiderman19
ID: 9872846
ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ? WHERE Warranty = ? ");
  ps2b = conn.prepareStatement("Update purchase SET ExpDateB = ? WHERE Warranty = ? ");
  if(warranty[j].length() > 0) {
           if (filter[j].equals("A")) {
               ps2a.setString( 1, date[j]);  
             //  ps2a.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps2a.setString(2, warranty[j]);
               number=ps2a.executeUpdate()+number;
          }
          if (filter[j].equals("B")) {
               ps2b.setString( 1, date[j]);
//               ps2b.setDate(2, new java.sql.Date(df.parse(todayDate).getTime()) );
               ps2b.setString(2, warranty[j]);
               number=ps2b.executeUpdate()+number;
          }

it's updated fine...

but i would like to update another field.. how??

do you think this is the error?

ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ?,  Date = ? WHERE Warranty = ? ");

ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ?, Date = ? WHERE Warranty = ? ");

the space between (ExpDateA=?, and Date )??
0
 

Author Comment

by:spiderman19
ID: 9872877
negative, after deleted the space in between the these 2.
0
 
LVL 92

Expert Comment

by:objects
ID: 9872881
whats the db schema?
0
 

Author Comment

by:spiderman19
ID: 9872909
purchase
======
Customer=text(25)
warranty=text(25)
ExpDateA=Date/Time
Date = Date/Time
0
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 9872918
try [Date]=?
0
 

Author Comment

by:spiderman19
ID: 9872949
can give me the full statement???
0
 

Author Comment

by:spiderman19
ID: 9872956
ps2a = conn.prepareStatement("Update purchase SET ExpDateA = ?,  [Date]= ? WHERE Warranty = ? ");
 
correct?
testing now...
0
 

Author Comment

by:spiderman19
ID: 9873022
DONE!!!

THANK YOU OBJECK...

i think the Date data field is reserved word of Java.. so have to use [].. thanks...
0
 
LVL 92

Expert Comment

by:objects
ID: 9873055
Woo hoo :-)))

I think it an Access reserved word.
0
 

Author Comment

by:spiderman19
ID: 9873105
THANK YOU!!!
0
 
LVL 92

Expert Comment

by:objects
ID: 9877186
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jAVA SERVLETS CODE FOR ONLINE SUPERMARKE 2 196
maven scope 1 126
lessBy10  challenge 15 92
if statement not resolving in my code 5 47
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now