我正在尝试按ISBN号搜索书籍。我在Oracle SQL Developer中有以下表格。按ISBN搜索书的SQL查询在SQL Developer中运行良好,但是当我尝试在JDBC中运行时,这个问题就进入了 其他部分并打印“找不到记录”虽然书架表中已有ISBN号。
当我在另一台PC上运行这个功能时,这个功能会被困在我的笔记本电脑中。这个是非常奇怪的错误。** 我能够在同一个表中运行插入函数,但无法运行搜索功能。
这个是在一台电脑上工作,而不是在另一台电脑上工作。可能是什么原因? 我最欢迎任何帮助。谢谢。
我有下面提到的3个表。我已经使用SearchISBN functionaliy
通过了我的代码CREATE TABLE Book(
ISBN INT NOT NULL PRIMARY KEY,
Title VARCHAR2(50),
PublisherID INT,
AuthorID INT,
PublishDate DATE,
AvailableCopies INT);
CREATE TABLE Author(
AuthorID INT NOT NULL PRIMARY KEY,
AuthorName VARCHAR2(50),
Email VARCHAR2(50)
);
CREATE TABLE Publisher(
PublisherID INT NOT NULL PRIMARY KEY,
PublisherName VARCHAR2(50),
Address VARCHAR2(50),
Phone INT
);
public static void FindByISBN(String[] args) throws SQLException
{
Scanner in = new Scanner(System.in);
int isbn, cnt=0;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
System.out.println("Enter ISBN Number:");
isbn = in.nextInt();
System.out.println("\n\tBook Search by ISBN\n");
conn = ConnectDB.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//////////////////////////////////////////// Query for Find Book
rs = stmt.executeQuery("SELECT b.isbn as isbn, b.title as title, a.name as aname, p.name as pname FROM book b, publisher p, author a where b.publisherid=p.publisherid "
+ " AND b.authorid=a.authorid AND b.isbn LIKE '%" + isbn + "%'");
/////////////////////////////////////////// Display Results
while(rs.next())
{
cnt+=1;
System.out.println(""+ rs.getInt("isbn") + "\t||\t" + rs.getString("title")+ "\t||\t"+ rs.getString("aname") + "\t||\t" +rs.getString("pname")+ "");
}
///////////////////////////////////////// If Output not found
if(cnt==0)
{
System.err.println("No Search Found !! \n");
}
} catch (SQLException ex) {
System.err.println("Error Message: " + ex.getMessage());
System.err.println("Error Code: " + ex.getErrorCode());
System.err.println("SQL State: " + ex.getSQLState());
}
finally{
if(rs != null){
rs.close();
}
if(stmt != null){
stmt.close();
}
if(conn != null){
conn.close();
}
}
}