我是 Java 数据库的初学者,谁能帮我解决这个问题。我想在我的 ms 访问文件中编辑一行,但出现“java.lang.NullPointerException”错误。谢谢
这是我的代码...
public void editBook(String inputTitle, String[] newBookInfo)
{
boolean result = false;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:database");
st = con.createStatement();
rs = st.executeQuery("select * from library");
while(rs.next())
{
if(boyerMoore(rs.getString("Title"), inputTitle))
{
rs.updateString("ISBN", newBookInfo[0]);
rs.updateString("Title", newBookInfo[1]);
rs.updateString("Author", newBookInfo[2]);
rs.updateString("Publisher", newBookInfo[3]);
rs.updateString("Published Year", newBookInfo[4]);
rs.updateString("Available Copies", newBookInfo[5]);
rs.updateString("Total Copies", newBookInfo[6]);
rs.updateRow();
rs.close();
st.close();
con.close();
JOptionPane.showMessageDialog(null, "Edit Succes", "Succes", JOptionPane.PLAIN_MESSAGE);
result = true;
}
}
if(!result)
JOptionPane.showMessageDialog(null, "\"" + inputTitle + "\" not Found in the Library", "Error", JOptionPane.ERROR_MESSAGE);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
}
}