ipoh1977
asked on
why it's contain more data?? ken, object, TomYates??
i have program like this.
//get information from user entry screen.
// contain 15 input text box with the same name of "warranty"
String [] warranty = request.getParameterValues ("warranty ");
string [] techcode = request.getParameterValues ("techcode ");
.
.
Connection conn=null;
ResultSet rs=null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
conn = DriverManager.getConnectio n("jdbc:od bc:myDSN") ;
PreparedStatement ps =null;
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
out.println("Warranty :" + warranty.length);
for (int j=0;j<warranty.length;j++) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
ps.executeQuery();
}
*******
and i tell you what happend. Although i only enter 3 rows data (including techcode, date, warranty, filter, tech_comm, dealer_comm), but after i hint the enter, it's going to print out this :
Warranty : 15
And this will cause me error since the rest of the data (started from 4 ) will contain null value.
Thus, i wonder what is happending.. and this cause me error...
Aren't it's (warranty.length) should only contain how many row i key in?
please help...
//get information from user entry screen.
// contain 15 input text box with the same name of "warranty"
String [] warranty = request.getParameterValues
string [] techcode = request.getParameterValues
.
.
Connection conn=null;
ResultSet rs=null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
Class.forName("sun.jdbc.od
conn = DriverManager.getConnectio
PreparedStatement ps =null;
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
out.println("Warranty :" + warranty.length);
for (int j=0;j<warranty.length;j++)
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
ps.executeQuery();
}
*******
and i tell you what happend. Although i only enter 3 rows data (including techcode, date, warranty, filter, tech_comm, dealer_comm), but after i hint the enter, it's going to print out this :
Warranty : 15
And this will cause me error since the rest of the data (started from 4 ) will contain null value.
Thus, i wonder what is happending.. and this cause me error...
Aren't it's (warranty.length) should only contain how many row i key in?
please help...
Sorry. A bit more explanation:
If your form contains 15 warranty fields, then all these values will be sent in the request (whether they contain data or not).
You might be able to leave out the test for null, but better to be safe than sorry ;-)
If your form contains 15 warranty fields, then all these values will be sent in the request (whether they contain data or not).
You might be able to leave out the test for null, but better to be safe than sorry ;-)
yeah, Jim is right :-)
tImyates ;-)
tImyates ;-)
ASKER
ok. let me test it out.
tImyates, so sorry about that....
:-) he...
tImyates, so sorry about that....
:-) he...
again......... got late...................... .....(thro wing mouse around..:-)) why everybody gets easy ones to answer!!!!
( no pun intended)
( no pun intended)
ASKER
but surprise it's contain all the 15 row of data... previously in my others code, i no need to check either it's contain null or not. The array will only contain "value" data...
anyway, no harm add the code in...
anyway, no harm add the code in...
ASKER
ai.... error again... i think this time is not as easy as above... i have to post the whole code.. sorry to confuse you...
*****
<%
boolean pass=false;
String techcode=request.getParame ter("techc ode");
String [] warranty = request.getParameterValues ("warranty ");
String [] filter = request.getParameterValues ("filter") ;
String [] date = request.getParameterValues ("date");
String [] dealer= request.getParameterValues ("dealer") ;
String [] tech_comm=request.getParam eterValues ("tech_com m");
String [] dealer_comm=request.getPar ameterValu es("dealer _comm");
for (int i=0; i<warranty.length;i++) {
if (filter[i]==null || date[i]==null || tech_comm[i]==null || dealer_comm==null ) {
pass=false;
break;
}
%>
<%
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
pass=true;
}
System.out.println("Pass"+ pass);
if (pass) {
int num=0;
try {
Connection conn=null;
ResultSet rs=null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
conn = DriverManager.getConnectio n("jdbc:od bc:myDSN") ;
PreparedStatement ps =null;
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
for (int j=0;j<warranty.length;j++) {
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
ps.executeQuery();
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
out.println("Warranty " + warranty[j]);
}
}
System.out.println("NUM"+n um);
} catch (Exception e) {
e.toString();
e.printStackTrace();
}
%>
******
I have this exception..
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eQuery(Jdb cOdbcPrepa redStateme nt.java:89 )
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 122)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
it's pointing to this line of code (tech_0005fconfirm$jsp.jav a:122),
>> ps.executeQuery();
*******
And before that i have make necessary checking...
1. All the data must be enter complete as one. (mean can not let date blanll or warranty blank etc..)
2. Parse the date and int so that it's match the database type.
what would be the wrong one?? any ideas? "General Errors".. ai... lausy exception...
Kludeep, challenging??
*****
<%
boolean pass=false;
String techcode=request.getParame
String [] warranty = request.getParameterValues
String [] filter = request.getParameterValues
String [] date = request.getParameterValues
String [] dealer= request.getParameterValues
String [] tech_comm=request.getParam
String [] dealer_comm=request.getPar
for (int i=0; i<warranty.length;i++) {
if (filter[i]==null || date[i]==null || tech_comm[i]==null || dealer_comm==null ) {
pass=false;
break;
}
%>
<%
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
pass=true;
}
System.out.println("Pass"+
if (pass) {
int num=0;
try {
Connection conn=null;
ResultSet rs=null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
Class.forName("sun.jdbc.od
conn = DriverManager.getConnectio
PreparedStatement ps =null;
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
for (int j=0;j<warranty.length;j++)
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
ps.executeQuery();
System.out.println(techcod
out.println("Warranty " + warranty[j]);
}
}
System.out.println("NUM"+n
} catch (Exception e) {
e.toString();
e.printStackTrace();
}
%>
******
I have this exception..
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
it's pointing to this line of code (tech_0005fconfirm$jsp.jav
>> ps.executeQuery();
*******
And before that i have make necessary checking...
1. All the data must be enter complete as one. (mean can not let date blanll or warranty blank etc..)
2. Parse the date and int so that it's match the database type.
what would be the wrong one?? any ideas? "General Errors".. ai... lausy exception...
Kludeep, challenging??
You shouldn't need the ";" on the end of your prepared statement (AFAIK).
I have to go out for a while now. Hopefully someone else may be able to help.
Possibly Tom ;-p
:-)
I have to go out for a while now. Hopefully someone else may be able to help.
Possibly Tom ;-p
:-)
*kicks Jim* ;-P
He's right though:
> ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
should be:
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
(no semi-colon) :-)
He's right though:
> ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
should be:
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
(no semi-colon) :-)
ASKER
jimmack, i can compile the whole code. No error.. and what is AFAIK??
ASKER
changed like what you suggested... same ...
ps = conn.prepareStatement("Ins ert into Service values(?,?,?,?,?,?)");
ps = conn.prepareStatement("Ins
The code will compile with the ";" in the SQL string, but I don't think it will run...
Have you tried it without the ";"?
> and what is AFAIK
As Far As I Know :-)
Have you tried it without the ";"?
> and what is AFAIK
As Far As I Know :-)
Same exception? odd...
what are the fieldnames in your table?
what are the fieldnames in your table?
ASKER
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eQuery(Jdb cOdbcPrepa redStateme nt.java:89 )
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 122)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.netbeans.modules.
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.netbeans.modules.
Ahhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhh hhhhhhhhhh hhhhhhhh!!
for (int j=0;j<warranty.length;j++) {
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
ps.executeQuery();
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
out.println("Warranty " + warranty[j]);
}
SHOULD BE:
for (int j=0;j<warranty.length;j++) {
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
ps.executeUpdate();
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
out.println("Warranty " + warranty[j]);
}
for (int j=0;j<warranty.length;j++)
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
ps.executeQuery();
System.out.println(techcod
out.println("Warranty " + warranty[j]);
}
SHOULD BE:
for (int j=0;j<warranty.length;j++)
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
ps.executeUpdate();
System.out.println(techcod
out.println("Warranty " + warranty[j]);
}
executeUpdate() NOT executeQuery() :-)
ASKER
this is the schema:
Table name:Service
Columns : TechName (text)
ServiceDate (Date/Time)
Warranty (Text)
Filter (Text)
TCom (Num - Long Integer)
DCom (Num - Long Integer)
this is the print out i added in before the ps.execute();
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
>> System.out.println(techcod e+":"+warr anty[j]+": "date[j]+" :"+filter[ j]+":"+tec h_comm[j]+ ":"+dealer _comm[j]);
ps.executeQuery();
and this is the error:
Passtrue
FKS:KELVIN:02/02/2003:A:12 :12
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eQuery(Jdb cOdbcPrepa redStateme nt.java:89 )
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 123)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
In fact i have entered 2 rows of data... but can't see the second one...
Table name:Service
Columns : TechName (text)
ServiceDate (Date/Time)
Warranty (Text)
Filter (Text)
TCom (Num - Long Integer)
DCom (Num - Long Integer)
this is the print out i added in before the ps.execute();
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
>> System.out.println(techcod
ps.executeQuery();
and this is the error:
Passtrue
FKS:KELVIN:02/02/2003:A:12
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
In fact i have entered 2 rows of data... but can't see the second one...
ASKER
Passtrue
FKS:KELVIN:02/02/2003:A:12 :12
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eUpdate(Jd bcOdbcPrep aredStatem ent.java:1 36)
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 123)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.se
*******
for (int j=0;j<warranty.length;j++) {
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
System.out.println(techcod e+":"+warr anty[j]+": "+date[j]+ ":"+filter [j]+":"+te ch_comm[j] +":"+deale r_comm[j]) ;
ps.executeUpdate();
out.println("Warranty " + warranty[j]);
}
FKS:KELVIN:02/02/2003:A:12
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
at javax.se
*******
for (int j=0;j<warranty.length;j++)
if ((warranty[j] != null) && (warranty[j].length() > 0)) {
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
System.out.println(techcod
ps.executeUpdate();
out.println("Warranty " + warranty[j]);
}
ASKER
Timyates... come back to you tomorroow...
thank for your time...
thank for your time...
Right...here we go... the definitive way to do it... this *will* work ;-)
---------------------
Connection conn=null;
try
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
conn = DriverManager.getConnectio n("jdbc:od bc:myDSN") ;
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].length() > 0))
{
PreparedStatement ps =null;
try
{
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
if( ps.executeUpdate() != 1 )
{
out.println( "Insert failed for " + warranty[ j ] ) ;
}
else
{
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
}
finally
{
try { if( ps != null ) ps.close() ; } catch( Exception ex ) { }
}
}
}
System.out.println("NUM"+n um);
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
try { if( conn != null ) conn.close() ; } catch( Exception ex ) { }
}
---------------------
Connection conn=null;
try
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
Class.forName("sun.jdbc.od
conn = DriverManager.getConnectio
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].length() > 0))
{
PreparedStatement ps =null;
try
{
ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
if( ps.executeUpdate() != 1 )
{
out.println( "Insert failed for " + warranty[ j ] ) ;
}
else
{
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod
}
finally
{
try { if( ps != null ) ps.close() ; } catch( Exception ex ) { }
}
}
}
System.out.println("NUM"+n
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
try { if( conn != null ) conn.close() ; } catch( Exception ex ) { }
}
You have to close your PreparedStatement between each insert...you cannot reuse it :-)
Hope that's ok!
(I havent compiled it, but it should work) :-)
Hope that's ok!
(I havent compiled it, but it should work) :-)
>> this *will* work ;-)
>> (I havent compiled it, but it should work) :-)
What was the conclusion on the ";" at the end of the statement (which I notice you've kept in) ?
>> (I havent compiled it, but it should work) :-)
What was the conclusion on the ";" at the end of the statement (which I notice you've kept in) ?
seems to work :-)
I guess it just gets ignored by the driver...
I guess it just gets ignored by the driver...
> (which I notice you've kept in)
Hehehe...I forgot to remove it ;-)
I think the problem here was reusing the PreparedStatement without first closing and reopening a new one...
maybe......
Hehehe...I forgot to remove it ;-)
I think the problem here was reusing the PreparedStatement without first closing and reopening a new one...
maybe......
OK :-)
didn't have time to read everything and try but here are my 2 cents:
>> ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
the sql statement is not correct. remove the ';' in the end. that will make access to think that's 2 statement and try to execute ';' after instert.
>> ps.executeQuery();
this shoudl be ps.executeUpdate() instead.
>> Aren't it's (warranty.length) should only contain how many row i key in?
warranty.length contains number of warrenty form fields in you form, the only exception to this is checkbox form field, which only returns those checked.
>> I think the problem here was reusing the PreparedStatement without first closing and reopening a new one...
PreparedStatement is designed to be executed multiple times without reopening. This isn't a problem.
If my comment contains answers already given by others, then ignore that part and accept others.
>> ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?);" );
the sql statement is not correct. remove the ';' in the end. that will make access to think that's 2 statement and try to execute ';' after instert.
>> ps.executeQuery();
this shoudl be ps.executeUpdate() instead.
>> Aren't it's (warranty.length) should only contain how many row i key in?
warranty.length contains number of warrenty form fields in you form, the only exception to this is checkbox form field, which only returns those checked.
>> I think the problem here was reusing the PreparedStatement without first closing and reopening a new one...
PreparedStatement is designed to be executed multiple times without reopening. This isn't a problem.
If my comment contains answers already given by others, then ignore that part and accept others.
I better have a crack now that everyone else has done the hard work :)
// Create your statement before the loop and reuse it for each iteration
PreparedStaement ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].trim().length () > 0))
{
try
{
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
if( ps.executeUpdate() != 1 )
{
out.println( "Insert failed for " + warranty[ j ] ) ;
}
else
{
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
}
}
}
// Create your statement before the loop and reuse it for each iteration
PreparedStaement ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].trim().length
{
try
{
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
if( ps.executeUpdate() != 1 )
{
out.println( "Insert failed for " + warranty[ j ] ) ;
}
else
{
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod
}
}
}
What's the catch?
Or should I say *Where*'s the catch ;-)
Or should I say *Where*'s the catch ;-)
you should probably also explicitly state the column names in your insert so there is no mismatching occurring.
ASKER
OK. guys.. i am back. Let me try one by one suggested by all the "Big name" here... he..
get back you one by one
get back you one by one
ASKER
First try, TimYates suggestion on Date: 12/02/2003 06:05AM PST --- same error... this time event worst.. no System.out.println() come out..but its pointing to the if( ps.executeUpdate() != 1 ) (tech_0005fconfirm$jsp.jav a:163) adn trust me, i hae remove the ";" in the preparedstatement. :-)
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eUpdate(Jd bcOdbcPrep aredStatem ent.java:1 36)
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 163)
>>you should probably also explicitly state the column names in your insert
object, is something like this?
PreparedStaement ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
or
PreparedStatement ps = conn.prepareStatement("Ins ert into Service (TechName, ServiceDate, Warranty, Filter, TCom,DCom) values (?,?,?,?,?,?)");
Hm... doesn't work also.... this is the error.
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eUpdate(Jd bcOdbcPrep aredStatem ent.java:1 36)
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 164)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.
and it's pointing to the same place of the code....
:-( I am crying already....
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
>>you should probably also explicitly state the column names in your insert
object, is something like this?
PreparedStaement ps = conn.prepareStatement( "Insert into Service values(?,?,?,?,?,?)" );
or
PreparedStatement ps = conn.prepareStatement("Ins
Hm... doesn't work also.... this is the error.
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.
and it's pointing to the same place of the code....
:-( I am crying already....
ASKER
Guys.. let's start from the very very basic one... since it's GENERAL ERROR...
why no one give comments on the database shcema that i have created?? i have a strong feeling on this...
have a look again.
Table name:Service
Columns : TechName (text)
ServiceDate (Date/Time)
Warranty (Text)
Filter (Text)
TCom (Num - Long Integer)
DCom (Num - Long Integer)
The catch is the Num-long integer.. i have no idea what is this long integer means.. and what i've planned to insert is 12.22 is possible. But for the testing that i have done, i only enter integer which is 12 ONLY.
Should i change ?? i mean the data type?? because it's look the code is all right...
why no one give comments on the database shcema that i have created?? i have a strong feeling on this...
have a look again.
Table name:Service
Columns : TechName (text)
ServiceDate (Date/Time)
Warranty (Text)
Filter (Text)
TCom (Num - Long Integer)
DCom (Num - Long Integer)
The catch is the Num-long integer.. i have no idea what is this long integer means.. and what i've planned to insert is 12.22 is possible. But for the testing that i have done, i only enter integer which is 12 ONLY.
Should i change ?? i mean the data type?? because it's look the code is all right...
ASKER
this is my code :
try
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
conn = DriverManager.getConnectio n("jdbc:od bc:myDSN") ;
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].length() > 0))
{
PreparedStatement ps =null;
try
{
ps = conn.prepareStatement("Ins ert into Service (TechName, ServiceDate, Warranty, Filter, TCom, DCom) values (?,?,?,?,?,?)");
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
if( ps.executeUpdate() != 1 ){
System.out.println( "Insert failed for " + warranty[ j ] ) ;
} else {
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod e+":"+warr anty[j]+": "+filter[j ]+":"+tech _comm[j]+" :"+dealer_ comm[j]);
}
finally
{
try { if( ps != null ) ps.close() ; } catch( Exception ex ) { ex.toString(); }
}
}
}
System.out.println("NUM"+n um);
}
catch( Exception e ) { e.printStackTrace(); }
finally
{
try { if( conn != null ) conn.close() ; } catch( Exception ex ) { }
}
and this is the error
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Jdbc Odbc.java: 6987)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (JdbcOdbc. java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQL Execute(Jd bcOdbc.jav a:3150)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut e(JdbcOdbc PreparedSt atement.ja va:214)
at sun.jdbc.odbc.JdbcOdbcPrep aredStatem ent.execut eUpdate(Jd bcOdbcPrep aredStatem ent.java:1 36)
at org.apache.jsp.tech_0005fc onfirm$jsp ._jspServi ce(tech_00 05fconfirm $jsp.java: 163)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:107 )
try
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
Class.forName("sun.jdbc.od
conn = DriverManager.getConnectio
for (int j=0;j<warranty.length;j++)
{
if ((warranty[j] != null) && (warranty[j].length() > 0))
{
PreparedStatement ps =null;
try
{
ps = conn.prepareStatement("Ins
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
if( ps.executeUpdate() != 1 ){
System.out.println( "Insert failed for " + warranty[ j ] ) ;
} else {
out.println("Warranty " + warranty[j]);
}
System.out.println(techcod
}
finally
{
try { if( ps != null ) ps.close() ; } catch( Exception ex ) { ex.toString(); }
}
}
}
System.out.println("NUM"+n
}
catch( Exception e ) { e.printStackTrace(); }
finally
{
try { if( conn != null ) conn.close() ; } catch( Exception ex ) { }
}
and this is the error
Passtrue
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcPrep
at sun.jdbc.odbc.JdbcOdbcPrep
at org.apache.jsp.tech_0005fc
at org.apache.jasper.runtime.
can you also check the lenght of text column of your table is big enough to hold your data?
you're unnecessarily recreating and closing your statement, though this is not related to your error.
try to do the insert directly into the database (without Java) and see if that gives you a better indictation of what the problem is.
try to do the insert directly into the database (without Java) and see if that gives you a better indictation of what the problem is.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And were you getting this error way back when this question began??
ASKER
ken, TQ for that. (Simulating the situation) for me.
I have check the Field Size, it's correct.
TechName - Filed Size=25
ServiceDate = default, no specific
Warranty = Filed Size=8
Filter = 2
TCom-Long integer- default
DCom - Long Integer-default
let me get you the whole page after i have changed like your page does...
Object,
>>And were you getting this error way back when this question began??
what does this mean?
I have check the Field Size, it's correct.
TechName - Filed Size=25
ServiceDate = default, no specific
Warranty = Filed Size=8
Filter = 2
TCom-Long integer- default
DCom - Long Integer-default
let me get you the whole page after i have changed like your page does...
Object,
>>And were you getting this error way back when this question began??
what does this mean?
> what does this mean?
Before you asked this question, were you getting this error "java.sql.SQLException: General error" ?
Before you asked this question, were you getting this error "java.sql.SQLException: General error" ?
ASKER
hm.. good idea.. hard code the value... let me see this:
ha... i've sovled it. Thank you for your brainstorming..... :-)
The answer for this is....
this is my original input page
input.jsp
======
Techcode : <input type="text" name="techcode" />
for (int i=0; i<10; i++) {
...
..
..}
and for my updateid.jsp
String [] techcode = request.getParameterValues ("techcode ");
everything look fine.. but for my Database, I HAVE SET THE TECHCODE AS A PRIMARY KEY!!!
and now it's going to insert a duplicate value while the techcode is still the same....
:-)
general error... i think thats mean by the databse error.. not the coding...
THANK YOU VERY ONe.. i am so happy for it........
ha... i've sovled it. Thank you for your brainstorming..... :-)
The answer for this is....
this is my original input page
input.jsp
======
Techcode : <input type="text" name="techcode" />
for (int i=0; i<10; i++) {
...
..
..}
and for my updateid.jsp
String [] techcode = request.getParameterValues
everything look fine.. but for my Database, I HAVE SET THE TECHCODE AS A PRIMARY KEY!!!
and now it's going to insert a duplicate value while the techcode is still the same....
:-)
general error... i think thats mean by the databse error.. not the coding...
THANK YOU VERY ONe.. i am so happy for it........
ASKER
By the way, the TCom and Dcom datatype, if it's going be long integer, can i insert 12.20 or 0.35?
or you think i should use Double or Integer??
or you think i should use Double or Integer??
use Double
ASKER
friend... got errors... but nothing to shown... what had happend to this code?
try {
} catch (Exception e) { e.printStackTrace(); }
is in the code
Connection conn = null;
PreparedStatement ps = null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy yy");
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
int num=0;
if (pass) {
try {
conn = DriverManager.getConnectio n("jdbc:od bc:myDSN") ;
ps = conn.prepareStatement("Ins ert into Service (TechName, ServiceDate, Warranty, Filter, TCom, DCom) values (?,?,?,?,?,?)");
for (int j=0;j<warranty.length;j++)
{
if(warranty[j].length() > 0) {
out.println(techcode+",");
out.println(warranty[j]+", ");
out.println(filter[j]+",") ;
out.println(tech_comm[j]+" ,");
out.println(dealer_comm[j] +"<br>");
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat e[j]).getT ime()) );
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm [j]));
ps.setInt(6, Integer.parseInt(dealer_co mm[j]));
ps.executeUpdate();
}
}
out.println("Num " +num);
} catch( Exception e ) {
e.printStackTrace();
but the entry doesnt go in yet.. no exception thrown...
try {
} catch (Exception e) { e.printStackTrace(); }
is in the code
Connection conn = null;
PreparedStatement ps = null;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy
Class.forName("sun.jdbc.od
int num=0;
if (pass) {
try {
conn = DriverManager.getConnectio
ps = conn.prepareStatement("Ins
for (int j=0;j<warranty.length;j++)
{
if(warranty[j].length() > 0) {
out.println(techcode+",");
out.println(warranty[j]+",
out.println(filter[j]+",")
out.println(tech_comm[j]+"
out.println(dealer_comm[j]
ps.setString( 1, techcode);
ps.setDate(2, new java.sql.Date(df.parse(dat
ps.setString(3, warranty[j]);
ps.setString(4, filter[j]);
ps.setInt(5, Integer.parseInt(tech_comm
ps.setInt(6, Integer.parseInt(dealer_co
ps.executeUpdate();
}
}
out.println("Num " +num);
} catch( Exception e ) {
e.printStackTrace();
but the entry doesnt go in yet.. no exception thrown...
whats the output?
ASKER
no output... nothing come out.. thats surpirse...
anyway, let me try my luck to troubleshoot first...
anyway, let me try my luck to troubleshoot first...
only way i could see that could happen is if pass is false.
o/wise at least this line "out.println("Num " +num);" would be executed.
or a stack trace
o/wise at least this line "out.println("Num " +num);" would be executed.
or a stack trace
>> e.printStackTrace();
try
e.printStackTrace( new java.io.PrintWriter( out ) );
try
e.printStackTrace( new java.io.PrintWriter( out ) );
Glad to know your problem is solved.
I feel guilty to get all the points since everybody helped here and there. I'm going to post points for you guys:
jimmack: https://www.experts-exchange.com/questions/20816494/points-for-jimmack.html
TimYates: https://www.experts-exchange.com/questions/20816495/points-for-TimYates.html
objects: https://www.experts-exchange.com/questions/20816497/points-for-objects.html
I feel guilty to get all the points since everybody helped here and there. I'm going to post points for you guys:
jimmack: https://www.experts-exchange.com/questions/20816494/points-for-jimmack.html
TimYates: https://www.experts-exchange.com/questions/20816495/points-for-TimYates.html
objects: https://www.experts-exchange.com/questions/20816497/points-for-objects.html
for (int j=0;j<warranty.length;j++)
ps.setString( 1, techcode);
to
for (int j=0;j<warranty.length;j++)
if ((warranty[j] != null) && (warranty[j].length() > 0))
{
ps.setString( 1, techcode);
.
.