?? duser.java
字號:
/*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/
package ch07.database;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import javax.servlet.http.HttpSession;
import ch07.*;
import ch07.object.unit.*;
/**
* 針對用戶信息(登錄)的數據處理類
* @author ShenYK
* @version 1.0
*/
public class DUser extends DCommon
{
public User getUserInfo ( String username,
String password )
throws Exception
{
//獲得數據庫連接
Connection conn = this.getDBConnection();
if ( conn == null )
{
throw new Exception("數據庫連接獲得失敗!");
}
Statement stmt = null;
ResultSet rs = null;
try
{
//檢查數據庫中是否已經有該用戶了
stmt = conn.createStatement();
//執行SQL語句
String sQuery = "select * from user "
+ "where username='" + username + "' "
+ "and password='" + password +"'";
rs = stmt.executeQuery( sQuery );
if ( rs.next() )
{
User oUser = new User(rs);
return oUser;
}
else
{
return null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
finally
{
try
{
rs.close();
stmt.close();
conn.close();
}catch(Exception ex)
{
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -