DBUser.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:1k
- package classmate;
- import javax.sql.DataSource;
- import java.sql.Connection;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class DBUser {
- DataSource dataSource;
-
- public DBUser(DataSource dataSource) {
-
- this.dataSource = dataSource;
- }
-
-
- public boolean checkUser(String name,String psw) throws Exception{
- Connection connect = null;
- String strSql;
- ResultSet rs;
- boolean result=false;
- strSql = "select * from classuser where username='"
- + name + "' and password='" + psw + "'";
- try {
- connect = dataSource.getConnection();
- Statement stmt = connect.createStatement();
- rs = stmt.executeQuery(strSql);
- if ( rs.next()) {
- result=true;
- }
- }
- catch(SQLException ex) {
- ex.printStackTrace();
- }
- finally{
- if(connect!=null)
- connect.close();
- }
- return result;
-
- }
-
- }