Ms Access sql problem

Reply

Join Date: Jun 2004
Posts: 11
Reputation: teritori is an unknown quantity at this point 
Solved Threads: 0
teritori teritori is offline Offline
Newbie Poster

Ms Access sql problem

 
0
  #1
Aug 11th, 2004
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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 153
Reputation: cosi is an unknown quantity at this point 
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: Ms Access sql problem

 
0
  #2
Aug 12th, 2004
>>result = statement.executeQuery("SELECT password FROM terry
WHERE username =@@@@@");

just put it right in ;-)
  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)

  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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4728 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC