📄 members.java
字号:
package lib;
import java.sql.*;
public class Members {
/***************************************************************************
*** declaration of the private variables used in the program ***
***************************************************************************/
private Connection connection = null;
private Statement statement = null;
private ResultSet resultSet = null;
private int memberID;
private int ID;
private String password;
private String name;
private String email;
private String major;
private int numberOfBooks;
private float money;
private Date expired;
private String URL = "jdbc:odbc:JLibrary";
private boolean type = true;
public Members() {
}
public void setType(boolean type){
this.type = type;
}
public boolean getType()
{
return this.type;
}
public int getMemberID() {
return memberID;
}
public int getID() {
return ID;
}
public String getPassword() {
return password;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public String getMajor() {
return major;
}
public int getNumberOfBooks() {
return numberOfBooks;
}
public float getMoney() {
return money;
}
public Date getExpired() {
return expired;
}
public void connection(String Query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Members.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Members.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(Query);
while (resultSet.next()) {
ID = resultSet.getInt("ID");
password = resultSet.getString("Password");
name = resultSet.getString("NAME");
if(type){
memberID = resultSet.getInt("MemberID");
email = resultSet.getString("EMAIL");
major = resultSet.getString("Major");
numberOfBooks = resultSet.getInt("NumberOfBooks");
money = resultSet.getFloat("Money");
expired = resultSet.getDate("Expired");}
}
resultSet.close();
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Members.java\n" + SQLe.toString());
}
}
public void update(String Query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Members.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Members.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.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
statement.executeUpdate(Query);
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Members.java\n" + SQLe.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -