| | |
jdbc sql statement
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 8
Reputation:
Solved Threads: 1
i am getting a problem in updating my database.
actually i am accessing two colums from my table and adding these two numbers ,
and the result i want to insert in the tables 3rd column
The statement i am using to access two columns
String str="select * from emp"
ResultSet rs=con.executeQuery(str);
while(rs.next())
{
int gs=rs.getInt("gross salary");
int al=rs.getInt("allowances"):
int total=gs+al;
con.updateQuery("insert into emp(total) values(total)");
}
i have a doubt about the statement
con.updateQuery("insert into emp(total) values(total)");
is it correct?
please help me out
actually i am accessing two colums from my table and adding these two numbers ,
and the result i want to insert in the tables 3rd column
The statement i am using to access two columns
String str="select * from emp"
ResultSet rs=con.executeQuery(str);
while(rs.next())
{
int gs=rs.getInt("gross salary");
int al=rs.getInt("allowances"):
int total=gs+al;
con.updateQuery("insert into emp(total) values(total)");
}
i have a doubt about the statement
con.updateQuery("insert into emp(total) values(total)");
is it correct?
please help me out
It should be like this:
"insert into emp(total) values("+total+")" if the total column is type NUMBER in the DB
or like this:
"insert into emp(total) values('"+total+"')"
Use System.out, before you are executing queries in order to see what is executed, so you can use it in an sql editor and debug:
"insert into emp(total) values("+total+")" if the total column is type NUMBER in the DB
or like this:
"insert into emp(total) values('"+total+"')"
Use System.out, before you are executing queries in order to see what is executed, so you can use it in an sql editor and debug:
Java Syntax (Toggle Plain Text)
Srtring s="insert into emp(total) values('"+total+"')"; System.out.println(s); con.updateQuery(s);
Check out my New Bike at my Public Profile at the "About Me" tab
If you are updating an existing record, you should be using You can either concatenate in the values of <total> and <empId> or use a PreparedStatement to set those variables. This means you need to capture whatever you are using for an id on that record in addition to the two values you want to add. Also, there is no updateQuery() in the java.sql.Statement interface. You need to call Statement.executeUpdate(java.lang.String)
Java Syntax (Toggle Plain Text)
update emp set total=<total> where id=<empId>
![]() |
Similar Threads
- Help connecting to mysql tables (JSP)
- Problem inserting data into database (JSP)
- using jdbc-odbc driver (Java)
- Error is [Microsoft][ODBC SQL Server Driver]Connection is busy (JSP)
- URGENT: JSP - StackOverFlow Error (JSP)
- somthing wrong about using JDBC-ODBC (JSP)
- IO and Embedded SQL (Java)
- Java JDBC ResultSet (Java)
- Ms Access sql problem (Java)
Other Threads in the Java Forum
- Previous Thread: JMF: video format and individual frames
- Next Thread: Problem updating a JLabel??
Views: 1247 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






