943,929 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4982
  • Java RSS
Aug 11th, 2004
0

Ms Access sql problem

Expand Post »
hi everyone

-In the code below, the line marked by *** is where i read my text field.
-The value of the text field is stored into a variable "InputUserName ".
-My question is: What do i put in the place of @@@@@ so as to have the same variable "InputUserName " referenced.
- I want to search/query my db by whatever the user enters as his username.
i'm on jdk1.5.0

Thanx in advance

Java Syntax (Toggle Plain Text)
  1. Driver d = (Driver)Class.forName"sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
  2. String URL = "jdbc:odbc:" + "CMSC446";
  3. con = DriverManager.getConnection( URL ,"","");
  4. statement = con.createStatement();
  5. *** InputUserName = username.getText(); //reading the Text field
  6. result = statement.executeQuery("SELECT password FROM terry
  7. WHERE username =@@@@@");
  8.  
  9. while(result.next())
  10. {
  11. InputPassword = Inpassword.getText(); //reading password field
  12.  
  13. String dbPassword = result.getString("password"); //obtaining db password
  14.  
  15. if (dbPassword.equals(InputPassword))
  16. {
  17. //aknowledge
  18. }
  19. else
  20. {
  21.  
  22. }
  23. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
teritori is offline Offline
11 posts
since Jun 2004
Aug 12th, 2004
0

Re: Ms Access sql problem

>>result = statement.executeQuery("SELECT password FROM terry
WHERE username =@@@@@");

just put it right in ;-)
Java Syntax (Toggle Plain Text)
  1. result = statement.executeQuery("SELECT password FROM terry
  2. WHERE username ="+InputUserName);

Just realise that executeQuery just takes in a String and you may compose Strings however way you want.
If InputUserName="cosi", then

"SELECT password FROM terry WHERE username="+InputUserName
equals
"SELECT password FROM terry WHERE username=cosi"

Only think you have to watch out for is you must encode your strings if you expect nonalphanumeric symbols. URLEncoder/URLDecoder is a cheap way to go about it...

An alternative strategy is to use PreparedStatements. (See http://java.sun.com/j2se/1.4.2/docs/...Statement.html)

Java Syntax (Toggle Plain Text)
  1. PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
  2. SET SALARY = ? WHERE ID = ?");
  3. pstmt.setBigDecimal(1, 153833.00)
  4. pstmt.setInt(2, 110592)

Hope this helps!

Ed
Reputation Points: 17
Solved Threads: 1
Junior Poster
cosi is offline Offline
153 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Help for my project
Next Thread in Java Forum Timeline: I need to re-write this code using a 'while' loop.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC