晕死,OK,sql语句和数据库的连接需要你进行相依修改,这个方法返回真就是说明用户和密码正确,返回假就是说明错误。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class LoginDao {
public boolean check(String name, String password) {
Connection conn = null;
PreparedStatement stm = null;
ResultSet res = null;
int num = 0;
String sql = "select count as CNT from user where userId= ? and password = ?";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.161.3 :1521:NMS", "用户名", "密码");
stm = conn.prepareStatement(sql);
stm.setString(1, name);
stm.setString(2, password);
res = stm.executeQuery();
if(res.next()){
num = res.getInt("CNT");
}
} catch (SQLException e) {
e.printStackTrace();
}
if(num>0)
return true;
else
return false;
}
}