📄 books.java
字号:
package lib;
import java.sql.*;
public class Books {
private Connection connection = null;
private Statement statement = null;
private ResultSet resultSet = null;
private int bookID;
private String subject;
private String title;
private String author;
private String publisher;
private int copyright;
private int edition;
private int pages;
private String ISBN;
private int numberOfBooks;
private int numberOfAvailbleBooks;
private int numberOfBorrowedBooks;
private String library;
private boolean availble;
private String URL = "jdbc:odbc:JLibrary";
public Books() {
}
public int getBookID() {
return bookID;
}
public String getSubject() {
return subject;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getPublisher() {
return publisher;
}
public int getCopyright() {
return copyright;
}
public int getEdition() {
return edition;
}
public int getPages() {
return pages;
}
public String getISBN() {
return ISBN;
}
public int getNumberOfBooks() {
return numberOfBooks;
}
public int getNumberOfAvailbleBooks() {
return numberOfAvailbleBooks;
}
public int getNumberOfBorrowedBooks() {
return numberOfBorrowedBooks;
}
public String getLibrary() {
return library;
}
public boolean getAvailble() {
return availble;
}
public ResultSet getResultSet(){
return resultSet;
}
public void connection(String Query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Books.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Books.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()) {
bookID = resultSet.getInt(1);
subject = resultSet.getString(2);
title = resultSet.getString(3);
author = resultSet.getString(4);
publisher = resultSet.getString(5);
copyright = resultSet.getInt(6);
edition = resultSet.getInt(7);
pages = resultSet.getInt(8);
ISBN = resultSet.getString(9);
numberOfBooks = resultSet.getInt(10);
numberOfAvailbleBooks = resultSet.getInt(11);
numberOfBorrowedBooks = resultSet.getInt(12);
library = resultSet.getString(13);
availble = resultSet.getBoolean(14);
}
resultSet.close();
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Books.java\n" + SQLe.toString());
}
}
public void update(String Query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfe) {
System.out.println("Books.java\n" + cnfe.toString());
}
catch (Exception e) {
System.out.println("Books.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("jdbc:odbc:JLibrary2");
connection = DriverManager.getConnection(URL);
statement = connection.createStatement();
statement.executeUpdate(Query);
statement.close();
connection.close();
}
catch (SQLException SQLe) {
System.out.println("Books.java\n" + SQLe.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -