Results 1 to 4 of 4
Thread: Mysql/JDBC update query problem
- 02-11-2009, 03:39 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 44
- Rep Power
- 0
Mysql/JDBC update query problem
Hi
I am trying to make an update query for java jdbc/mysql.
The query runs as follows:-
result = statement.executeUpdate("update account set balance = balance - " + amountToWithdraw +
" where account.account_number = '" + accountNumber + "'" + "and account.sortcode = " + "'"+sortCode+"'");
I keep getting the error message:-
Account.java:126: incompatible types
found : int
required: java.sql.ResultSet
result = statement.executeUpdate("update account set balance = balance - " + amountToWithdraw +
^
1 error
I know that the syntax is correct because I have it working in mysql, I dont quite know what this means.
Any help would be appreciated
theLinuxGuy
- 02-11-2009, 05:02 PM #2
Member
- Join Date
- Dec 2008
- Posts
- 44
- Rep Power
- 0
Problem Resolved
Hi
I have corrected the mistake - the problem was I had adjusted a select query that had used a result set with the statement connection, but when executing an update there is no such result set, nothing is returned from the query so there is no result set.
I corrected the query by simply adding the line statement = connection.createStatement(); and removed the previous line statement = connection.createStatement(//resultSetdetails);.
as follows if it helps anybody ever!
public int makeWithdrawel(int amountToWithdrawIn)
{
amountToWithdraw = amountToWithdrawIn;
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/atm";
Connection connection = DriverManager.getConnection(
url, "user", "password");
statement = connection.createStatement();
statement.executeUpdate("update account set balance = balance - " + amountToWithdraw +
" where account.account_number = '" + accountNumber + "'");
connection.close();
}
- 02-11-2009, 05:26 PM #3
Just an off-topic suggestion. Look into using PreparedStatement. It seems like a pain in the aft, but CreateStatement is *very*, as in noticeable, slow. You can reuse prepared statements, they are easier to write and debug, and the stop SQL injection attacks.
- 02-11-2009, 09:56 PM #4
Member
- Join Date
- Dec 2008
- Posts
- 44
- Rep Power
- 0
Similar Threads
-
Java JDBC/MySQL appropriate Syntax
By thelinuxguy in forum Advanced JavaReplies: 7Last Post: 02-10-2009, 07:57 PM -
How to pass mysql string through a url parameter to a detail page query
By kwesiaryee in forum New To JavaReplies: 1Last Post: 08-22-2008, 06:28 PM -
ms access jdbc query problem
By Fleur in forum New To JavaReplies: 2Last Post: 04-30-2008, 06:55 PM -
unable to update MYSQL with values from jsp page
By koushika in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-27-2008, 01:35 AM -
help ... JDBC or PHP/MySQL
By bluebarca in forum Advanced JavaReplies: 1Last Post: 11-16-2007, 10:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks