Results 1 to 2 of 2
  1. #1
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Rep Power

    Default Updating SQL table through PreparedStatement's


    I'm trying to update a value that keeps track of products in stock of a store.
    The database is an MS Access database, and I'm using the JDBC to read and set values to it.

    The last step in my program is to change the value of "in stock" of a certain product. I get no exceptions, and running it in debug mode I clearly see that the values are correct.

    lssaldo = an integer read from the textfield that the user has input a value to.
    spelNamn = game name, i.e. "Diablo". This is read from a JLabel.
    bAdress = store address, i.e. "Playstreet 12". Read from a ComboBox value.

    My SQL statement works in Access, though when I run this in Java, nothing happens. The code executes, but there is not update being made.

    The connection to the database is established as a dialog where all the inputs are being made is opened. It fetches data perfectly. As can be seen in the code below, I'm using the same connection to update the table.
    I've restarted the program after I've made an update, thinking there might be something cached (?) or similar, though the problem consist.

    Can anyone spot something that I have missed?

    I know that this is not a runnable peace of code, only the method that I have written to update my database. I don't think the error is great, so I wouldn't create a SSCCE for this. I am grateful for any help or tips I can receive!

    Java Code:
    		public void setStoreSaldo() throws SQLException{
    		PreparedStatement ps;
    		String sqlSetSaldo = "UPDATE Lagersaldo ls, Butik b, Produkt p SET ls.Antal = ? WHERE p.Streckkod = ls.produkt AND  ls.Butik = b.ID AND p.Speltitel = ? AND b.Gatuadress = ?";
    		ps = con.prepareStatement(sqlSetSaldo);
    		int lssaldo = Integer.parseInt(tf_saldo.getText());
    		String spelNamn = lbl_spel_disp.getText();
    		String bAdress = (String) cb_store.getItemAt(cb_store.getSelectedIndex());
    		ps.setInt(1, lssaldo);
    		ps.setString(2, spelNamn);
    		ps.setString(3, bAdress);
    Last edited by Zyril; 12-28-2012 at 04:25 PM.

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Rep Power

    Default Re: Updating SQL table through PreparedStatement's

    I came to realise that I had some bad keys in my database that I am looking over right now. Perhaps the problem lies there.

Similar Threads

  1. Using PreparedStatement with table name
    By abhi7080 in forum New To Java
    Replies: 8
    Last Post: 12-19-2011, 01:13 PM
  2. Getting exception when updating the table.
    By Chinnu55 in forum Advanced Java
    Replies: 1
    Last Post: 07-14-2011, 06:00 PM
  3. Updating Displayed Table Rows
    By raycini in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 04-20-2009, 08:24 AM
  4. Replies: 0
    Last Post: 02-09-2008, 08:31 PM
  5. Replies: 0
    Last Post: 02-09-2008, 08:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts