Results 1 to 10 of 10
Thread: SQL update problem
- 11-19-2008, 10:29 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
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.
- 11-19-2008, 10:32 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 11-19-2008, 10:32 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How you convert an int value to string?
- 11-19-2008, 10:34 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Here is how I convert from int to string
right out of the profesor's notes.
ic = Integer.toString(val);
- 11-19-2008, 10:43 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 11-19-2008, 04:40 PM #6
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Thanks
it works now I would have never tried that.
- 11-21-2008, 04:22 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please mark the thread solved if you found the solution for your question.
- 11-21-2008, 10:41 AM #8
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
I tried to mark it as solved
I am very new here and I couldn't locate how to do it sorry.
- 11-21-2008, 06:45 PM #9
at the top of the post click thread tools then click on solved
- 11-21-2008, 06:54 PM #10
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
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
-
JPanel won't update
By ibanez270dx in forum New To JavaReplies: 3Last Post: 01-06-2009, 08:59 PM -
Auto Update Function
By abiieez in forum New To JavaReplies: 4Last Post: 04-16-2008, 04:17 PM -
Using sql:update tag
By Java Tip in forum Java TipReplies: 0Last Post: 01-13-2008, 11:49 PM -
Java Update Installation
By guest in forum New To JavaReplies: 1Last Post: 12-01-2007, 04:36 AM -
dynamic update in swt
By sandor in forum SWT / JFaceReplies: 0Last Post: 05-14-2007, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks