Title: storing a password into an ms access database from a servlet page
Tags: servlets
Question: I am getting username and password from the user in a registration form and saving the same in MS access database. When I do that, the password column in my database shows "null". So the login page does not work properly. What do I do?
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("Jdbc:Odbc:db5");
Statement smt = con.createStatement();
String str =
"insert into table1(name1,sex,age,email,pwd,info) "
+ "values('" + name + "','" + sex + "','" + age + "','"
+ email + "','" + pwd + "','" + info + "')";
int val=smt.executeUpdate(str);
Comment: You shouldn't be storing wwilliams@example.org. You should store *hashes* of the passwords. This has ***very important legal consequences.*** Send the word 'non-repudation' up to your corporate lawyers.

Comment: yes thank you just now I checked, the value of pwd is null, I tried with manual values, it is showing the output, I'll check for mistakes in my code. Thanks a lot!

Comment: First and foremost thing is to replace that Statement with `PreparedStatement` to prevent SQL injection attack.

Comment: It's not clear how you are retrieving the password from servlet. Did you try printing it before persisting in the database to see if it is not null?


Here is another answer: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("Jdbc:Odbc:db5");
Statement smt = con.createStatement();
String str =
"insert into table1(name1,sex,age,email,pwd,info) "
+ "values('" + name + "','" + sex + "','" + age + "','"
+ email + "','" + pwd + "','" + info + "')";
smt.executeUpdate(str);

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:10/27/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<servlets>', 'Title': 'storing a password into an ms access database from a servlet page', 'ViewCount': 370, 'id': 13098584, 'user_AboutMe': None, 'user_AccountId': 1982837.0, 'user_DisplayName': 'Mahemaa Iyer', 'user_Reputation': 1.0, 'user_Views': 9.0, 'user_id': 1778989.0}}