📄 databasequery.java~53~
字号:
{
try
{
String sql="select * from BookInformation where bookIndex="+book.book.getBookIndex();
rSet=DatabaseConnection.statement.executeQuery(sql);
//System.out.println(books.getBookName()+books.getBookType());
//System.out.println(book.book.getBookIndex());
//rSet.next();
//System.out.println(rSet.getString("bookName"));
if(rSet.next()==false)
{
System.out.println(22222);
rSet.close();
return false;
}
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////
//query bookInformation to gain the information of one book with the input Index
/////////////////////////////////////////////////////////////////////////
public static Vector bookInformationQueryForInformationWithIndex(Books books,Vector vector)
{
Books bookOne=new Books();
try
{
String sql="select * from BookInformation where bookIndex="+books.book.getBookIndex();
rSet=DatabaseConnection.statement.executeQuery(sql);
while(rSet.next()!=false)
{
/*System.out.println("begin");
bookOne.setISBN(rSet.getString("ISBN"));
bookOne.book.setBookIndex(rSet.getInt("bookIndex"));
bookOne.setBookName(rSet.getString("bookName"));
bookOne.setWriter(rSet.getString("writer"));
bookOne.setBookType(rSet.getString("bookType"));
bookOne.setPress(rSet.getString("press"));
bookOne.setPublishTime(rSet.getString("publishTime"));
bookOne.book.setBookState(rSet.getString("bookState"));
bookOne.setShelf(rSet.getString("shelf"));
vector.addElement(bookOne);
System.out.println(vector.size());*/
Vector rec_vector = new Vector();
rec_vector.addElement(rSet.getString("ISBN"));
rec_vector.addElement(String.valueOf(rSet.getInt("bookIndex")));
rec_vector.addElement(rSet.getString("bookName"));
rec_vector.addElement(rSet.getString("writer"));
rec_vector.addElement(rSet.getString("bookType"));
rec_vector.addElement(rSet.getString("press"));
rec_vector.addElement(rSet.getString("publishTime"));
rec_vector.addElement(rSet.getString("bookState"));
rec_vector.addElement(rSet.getString("shelf"));
vector.addElement(rec_vector); // 向量rec_vector加入向量vector中
}
rSet.close();
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return vector;
}
////////////////////////////////////////////////////////////////////////////
// query BooksList to whether the book exist with the input name
////////////////////////////////////////////////////////////////////////////
public static boolean bookInformationQueryForWhetherExistWithName(Books books)
{
try
{
String sql="select * from BookInformation where bookName='"+books.getBookName()+"'";
rSet=DatabaseConnection.statement.executeQuery(sql);
if(rSet.next()==false)
{
rSet.close();
return false;
}
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////
//query bookInformation to gain the information of one book with the name Index
/////////////////////////////////////////////////////////////////////////
public static Vector bookInformationQueryForInformationWithName(Books books,Vector vector)
{
Books bookOne=new Books();
try
{
String sql="select * from BookInformation where bookName='"+books.getBookName()+"'";
rSet=DatabaseConnection.statement.executeQuery(sql);
while(rSet.next()!=false)
{
Vector rec_vector = new Vector();
rec_vector.addElement(rSet.getString("ISBN"));
rec_vector.addElement(String.valueOf(rSet.getInt("bookIndex")));
rec_vector.addElement(rSet.getString("bookName"));
rec_vector.addElement(rSet.getString("writer"));
rec_vector.addElement(rSet.getString("bookType"));
rec_vector.addElement(rSet.getString("press"));
rec_vector.addElement(rSet.getString("publishTime"));
rec_vector.addElement(rSet.getString("bookState"));
rec_vector.addElement(rSet.getString("shelf"));
vector.addElement(rec_vector); // 向量rec_vector加入向量vector中
}
rSet.close();
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return vector;
}
////////////////////////////////////////////////////////////////////////////
// query BooksList to whether the book exist with the input name
////////////////////////////////////////////////////////////////////////////
public static boolean bookInformationQueryForWhetherExistWithType(Books books)
{
try
{
String sql="select * from BookInformation where bookName='"+books.getBookType()+"'";
rSet=DatabaseConnection.statement.executeQuery(sql);
if(rSet.next()==false)
{
rSet.close();
return false;
}
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////
//query bookInformation to gain the information of one book with the name Type
/////////////////////////////////////////////////////////////////////////
public static Vector bookInformationQueryForInformationWithType(Books books,Vector vector)
{
Books bookOne=new Books();
try
{
String sql="select * from BookInformation where bookName='"+books.getBookType()+"'";
rSet=DatabaseConnection.statement.executeQuery(sql);
while(rSet.next()!=false)
{
Vector rec_vector = new Vector();
rec_vector.addElement(rSet.getString("ISBN"));
rec_vector.addElement(String.valueOf(rSet.getInt("bookIndex")));
rec_vector.addElement(rSet.getString("bookName"));
rec_vector.addElement(rSet.getString("writer"));
rec_vector.addElement(rSet.getString("bookType"));
rec_vector.addElement(rSet.getString("press"));
rec_vector.addElement(rSet.getString("publishTime"));
rec_vector.addElement(rSet.getString("bookState"));
rec_vector.addElement(rSet.getString("shelf"));
vector.addElement(rec_vector); // 向量rec_vector加入向量vector中
}
rSet.close();
}
catch(SQLException ex)
{ // 捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
return vector;
}
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -