| | |
Ms Access sql problem
![]() |
•
•
Join Date: Jun 2004
Posts: 11
Reputation:
Solved Threads: 0
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
-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)
Driver d = (Driver)Class.forName"sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); String URL = "jdbc:odbc:" + "CMSC446"; con = DriverManager.getConnection( URL ,"",""); statement = con.createStatement(); *** InputUserName = username.getText(); //reading the Text field result = statement.executeQuery("SELECT password FROM terry WHERE username =@@@@@"); while(result.next()) { InputPassword = Inpassword.getText(); //reading password field String dbPassword = result.getString("password"); //obtaining db password if (dbPassword.equals(InputPassword)) { //aknowledge } else { } }
>>result = statement.executeQuery("SELECT password FROM terry
WHERE username =@@@@@");
just put it right in ;-)
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)
Hope this helps!
Ed
WHERE username =@@@@@");
just put it right in ;-)
Java Syntax (Toggle Plain Text)
result = statement.executeQuery("SELECT password FROM terry 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)
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?"); pstmt.setBigDecimal(1, 153833.00) pstmt.setInt(2, 110592)
Hope this helps!
Ed
![]() |
Similar Threads
- convert MS Access to MS SQL Server (VB.NET)
- Difference between ms access and sql (Visual Basic 4 / 5 / 6)
- Weird ASP/SQL Problem (ASP)
- QUICK! Access SQL using ASP and javascript (ASP)
- Problem with URL access to SQL Server 2000 db (RSS, Web Services and SOAP)
Other Threads in the Java Forum
- Previous Thread: Help for my project
- Next Thread: I need to re-write this code using a 'while' loop.
Views: 4728 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
add android applet application arguments array arraylist arrays binary bluetooth build c# chat class classes client code combobox compiler component convert data database desktop detection draw eclipse error event exception fast file fractal game givemetehcodez graphics gridlayout gui helpwithhomework html ide image images input integer j2me java javafx jframe jmf jpanel jtable jtextfield key linked linked-list list loop main method methods mobile netbeans newbie node number object oracle output parameter pattern phone print printing problem program programming project read remote remove robot scanner screen search server service set size sms socket sort source sql string swing test text transfer tree





