建立一個登入系統,需達成:
public boolean checkUser() throws Exception {
boolean flag = false;
ResultSet rs = conn.executeQuery(getSql());
if (rs.next()) {
userID = rs.getString("userID");
userName = rs.getString("userName");
userPWD = rs.getString("userPWD");
userUnit = rs.getString("userUnit");
userLoadTime = rs.getDate("userLoadTime");
userLoadNumeric = rs.getInt("userLoadNumber");
flag = true;
}
rs.close();
conn.closeConn();
return flag;
}
透過回傳值判定使用者是否存在。
public void changeLoginInfo(String userID) throws Exception {
String sql = "UPDATE SystemUserTable SET UserLoadTime=sysdate, " +
"UserLoadNumber=UserLoadNumber+1 WHERE userID='" + userID + "'";
conn.executeUpdate(sql);
}
CREATE OR REPLACE PROCEDURE proc_writeNote(
description IN VARCHAR2,
wName IN VARCHAR2,
wIP IN VARCHAR2
) IS
BEGIN
INSERT INTO Systemnote (Id, Description, Wname, Wip)
VALUES (Autoaddid.Nextval, description, wName, wIP);
COMMIT;
END proc_writeNote;
public CallableStatement prepareCall(String produce) {
try {
conn = DriverManager.getConnection(DBUrl, UserID, UserPWD);
cstmt = conn.prepareCall(produce);
} catch (SQLException ex) {
System.err.print("prepareCall():" + ex.getMessage());
}
return cstmt;
}
public void writeNote(String description, String wName, String wIP) {
String sql = "{call proc_writeNote(?,?,?)}";
try {
CallableStatement cstmt = conn.prepareCall(sql);
cstmt.setString(1, description);
cstmt.setString(2, wName);
cstmt.setString(3, wIP);
cstmt.executeUpdate();
} catch (SQLException ex) {
System.out.print("writeNote():" + ex.getMessage());
}
}