Results 1 to 10 of 10
  1. #1
    skiing is offline Member
    Join Date
    Nov 2008
    Posts
    15
    Rep Power
    0

    Default SQL update problem

    I am having problems updating my sql database with java I am passing in a string value that I have converted from a int to a string and have the value for the colum set to text here is what I have

    statement2 = "update Mortgage SET Number1 = '" + ic + "' WHERE ID = '" + 1 + "'";


    it will erase what I have in there and leave a blank but wont insert like 5000, but right before it I print out a system.out.println(ic) and it prints out 5000.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    skiing is offline Member
    Join Date
    Nov 2008
    Posts
    15
    Rep Power
    0

    Default Here is how I convert from int to string

    right out of the profesor's notes.

    ic = Integer.toString(val);

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Like I said, though, use PreparedStatement, it may or may not solve the current problem, but it will, at least, prevent many possible future problems.

    If your instructor is telling you to cobble together a statement like this then you should shoot him for ineptitude. Cobbling together statements in this manner is just begging for problems (and SQL Injection attacks).

    Edit: And yes, I know, you and your instructor (if he is the one that directed you to use this) will say, "It is only for now" and/or "for this example it doesn't matter". And you're right, unfortunately it breeds bad habits. Once you've learned to do it this way (and believe it to be the right way), you won't "change your stripes", so to say. Thereby running into all sorts of problems later. Do it right, now.
    Last edited by masijade; 11-19-2008 at 10:46 AM.

  6. #6
    skiing is offline Member
    Join Date
    Nov 2008
    Posts
    15
    Rep Power
    0

    Default Thanks

    it works now I would have never tried that.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  8. #8
    skiing is offline Member
    Join Date
    Nov 2008
    Posts
    15
    Rep Power
    0

    Default I tried to mark it as solved

    I am very new here and I couldn't locate how to do it sorry.

  9. #9
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    at the top of the post click thread tools then click on solved

  10. #10
    skiing is offline Member
    Join Date
    Nov 2008
    Posts
    15
    Rep Power
    0

    Default Thanks

    I am a student doing a project for a class that the program I am writting is 80% of my grade and I have been basically teaching myself java by trial and error and little help from the profesor. You have helped answer two or three major stumbling points on my project that would not have been finished without your help.

Similar Threads

  1. JPanel won't update
    By ibanez270dx in forum New To Java
    Replies: 3
    Last Post: 01-06-2009, 08:59 PM
  2. Auto Update Function
    By abiieez in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 04:17 PM
  3. Using sql:update tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 11:49 PM
  4. Java Update Installation
    By guest in forum New To Java
    Replies: 1
    Last Post: 12-01-2007, 04:36 AM
  5. dynamic update in swt
    By sandor in forum SWT / JFace
    Replies: 0
    Last Post: 05-14-2007, 08:32 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
  •