package com.conn;
import java.sql.*;
public class Login {
public int isLogin(String name,String pwd){
int flag=0;
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;
//加载驱动
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
//连接数据库
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Psychology","root","123456");
String sql="select * from users where username=? and userpassword=?";
pst=conn.prepareStatement(sql);
pst.setString(1,name);
pst.setString(2,pwd);
rs=pst.executeQuery();
if(rs.next())
flag=1;
} catch (Exception ex) {
ex.printStackTrace();
}finally{
try {
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return flag;
}
}