?? borrow.java
字號:
package lib;
import java.sql.*;
public class Borrow {
private Connection connection = null;
private Statement statement = null;
private ResultSet resultSet = null;
private int bookID;
private int memberID;
private Date dayOfBorrowed;
private Date dayOfReturn;
private String URL = "jdbc:odbc:JLibrary";
public Borrow() {
}
public int getBookID() {
return bookID;
}
public int getMemberID() {
return memberID;
}
public Date getDayOfBorrowed() {
return dayOfBorrowed;
}
public Date getDayOfReturn() {
return dayOfReturn;
}
public void connection(String sql) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Borrow.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Borrow.java\n" + e.toString());
}
/***************************************************************
* for making the connection,creating the statement and update *
* the table in the database. After that,closing the statmenet *
* and connection. There is catch block SQLException for error *
***************************************************************/
try {
connection = DriverManager.getConnection(URL);
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
bookID = resultSet.getInt(1);
memberID = resultSet.getInt(2);
dayOfBorrowed = resultSet.getDate(3);
dayOfReturn = resultSet.getDate(4);
}
resultSet.close();
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Borrow.java\n" + SQLe.toString());
}
}
public void update(String Query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Borrow.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Borrow.java\n" + e.toString());
}
/***************************************************************
* for making the connection,creating the statement and update *
* the table in the database. After that,closing the statmenet *
* and connection. There is catch block SQLException for error *
***************************************************************/
try {
connection = DriverManager.getConnection(URL);
statement = connection.createStatement();
statement.executeUpdate(Query);
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Borrow.java\n" + SQLe.toString());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -