📄 todatabase.java
字号:
//import the packages for using the classes in them into the program
import java.sql.*;
public class toDatabase {
/***************************************************************************
*** declaration of the private variables used in the program ***
***************************************************************************/
//for setting the connection and statement
private Connection connection = null;
private Statement statement = null;
private ResultSet resultset = null;
public boolean isDouble(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(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:JLibrary");
statement = connection.createStatement();
resultset = statement.executeQuery(query);
while(resultset.next()) {
return true;
}
resultset.close();
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
return false;
}
public int numberOfBooks(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(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:JLibrary");
statement = connection.createStatement();
resultset = statement.executeQuery(query);
while(resultset.next()) {
return resultset.getInt("NumberOfBooks");
}
resultset.close();
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
return -1;
}
public int memberID(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(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:JLibrary");
statement = connection.createStatement();
resultset = statement.executeQuery(query);
while(resultset.next()) {
return resultset.getInt("MemberID");
}
resultset.close();
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
return -1;
}
public void update(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(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:JLibrary");
statement = connection.createStatement();
statement.executeUpdate(query);
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -