新问题:我想查询数据库,内容用自己的参数输入,但老不对,只能输出failed(这是我自己做测试用的,成功的话为success)大家帮忙看看啊
package message;
import java.sql.*;
public class MessageLogin
{
private String name,password;
public void setname(String name){
this.name=name;
}
public String getname(){
return name;
}
public String getpassword(){
return password;
}
public void setpassword(String password){
this.password=password;
}
public String getMessage(String name,String password){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
con=DriverManager.getConnection("jdbc:odbc:netbook","sa","442352");
stmt=con.createStatement();
String str="select *from jacky.dbo.message";
rs=stmt.executeQuery(str);
while(rs.next()){
String na=rs.getString("name");
String ps=rs.getString("password");
System.out.println(na);//这两个都是能正确输出的
System.out.println(ps);
if(na.equals(name)&&password.equals(ps)){
System.out.println("success");
}
else{
System.out.println("failed");
}
}
}
catch(Exception e){
}
}
public static void main(String args[]){
MessageLogin login=new MessageLogin();
String str=login.getMessage("jacky","123");//测试语句
}
}
[此贴子已经被作者于2007-11-20 20:40:55编辑过]