Results 1 to 6 of 6
Thread: SQL Update with ? as values
- 04-02-2011, 11:04 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
SQL Update with ? as values
Hi, I am trying to get the password collumn in my database to update with a new password from which the user will enter into a Java GUI. The Java side is working fine, however my SQL is complaining saying that 'ERROR: null value in column "password" violates not-null constraint'. Even though I am actually specifying a value. Here is the UPDATE statement:
public static void updatePassword(String password, int userID) {
Connection connection = connectionDB.createConnection();
try {
PreparedStatement stmt = connection.prepareStatement("UPDATE login "
+ "SET password = ?"
+ "WHERE login_id = ?");
stmt.setString(1, password);
stmt.setInt(2,userID);
stmt.execute();
} catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println("Password" +password);
System.out.println("UserID"+ userID); // It is finding the correct userID but not updating the password for that user!
}
If anyone can help, thats great :)
- 04-02-2011, 01:24 PM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Replace this
byJava Code:PreparedStatement stmt = connection.prepareStatement("UPDATE login " + "SET password = ?" + "WHERE login_id = ?"); stmt.setString(1, password); stmt.setInt(2,userID); stmt.execute();
Java Code:PreparedStatement stmt = connection.prepareStatement("UPDATE login SET password = ' +"password"+ ' WHERE login_id = ' +"userID"+ '); stmt.execute();Don't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 04-02-2011, 02:16 PM #3
- 04-02-2011, 03:14 PM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
- 04-02-2011, 06:53 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 15
- Rep Power
- 0
If thats subject to SQL Injection then I can't really use it. Thanks for the suggestion though. Any other idea's? Thanks
-
Are you familiar with the SQL injection issue? If not, you should understand it first before giving SQL advice, and you can find all about it on Google and in fact in Wikipedia.
Similar Threads
-
need to input values from a text file into an array and count values
By pds8475 in forum New To JavaReplies: 14Last Post: 01-22-2011, 02:36 PM -
How to update JTextArea with JSlider Values
By theen3my in forum AWT / SwingReplies: 7Last Post: 10-04-2009, 08:48 AM -
Retaining DB values as well as Dynamically generated Values.. Help Needed !
By rajivjha in forum Advanced JavaReplies: 0Last Post: 05-22-2008, 10:53 AM -
Accessing boolean Values of another values in one class.
By a_iyer20 in forum Advanced JavaReplies: 4Last Post: 04-15-2008, 01:04 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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks