不知道哪里错了
public class DataBase {Connection conn;
ResultSet rs;
Statement st;
int count;//记录次数
public static Login log;//创建登录窗口引用
public static String message = "127.0.0.1:3306";//声明一个静态成员变量
public DataBase() {
// TODO 自动生成的构造函数存根
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://"+message+"/test","root","520");
st =conn.createStatement();
}
catch(Exception e) {
JOptionPane.showMessageDialog(log, "用户IP或端口号错误!!","信息",JOptionPane.INFORMATION_MESSAGE);
return;
}
}
public int selectDb(String sql) {
try {rs = st.executeQuery(sql);
}
catch(Exception e) {
e.printStackTrace();
}
return count;
}
public int updateDb(String sql) {
try {
//sql = new String(sql.getBytes(),"ISO-8859-1");
count = st.executeUpdate(sql);
}
catch(Exception e) { e.printStackTrace();}
return count;
}
public void dbClose() {
try {conn.close();}
catch(Exception e) { e.printStackTrace();}
}
}
public class BookManage extends JFrame implements ActionListener {
.......
public void searchBook() {
String[] strl = new String[7];
strl[0] = jf[0].getText().trim();
if(strl[0].equals("")) {
JOptionPane.showMessageDialog(this, "请输入书籍号!","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
else {
try{
sql = "select * from book where BookNO=" + Integer.parseInt(strl[0]);
db = new DataBase();
db.selectDb(sql);
Vector<String> v = new Vector<String>();
if(db.rs.next()) {
for(int i=0; i<=6; i++) {
strl[i]=db.rs.getString(i++);
v.add(strl[i]);
}
v_data.add(v);
}
else{
JOptionPane.showMessageDialog(this,"没有找到该书,请重新输入!","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
dtm.setDataVector(v_data, v_head);
jtb.updateUI(); jtb.repaint();
db.dbClose();
}
catch(Exception e) { e.printStackTrace();}
}
}
.......
}
结果编译了一下后发现出现了下面的错误,不知道哪里错了,请大神指教!!
java.lang.NullPointerException
at tushu.DataBase.selectDb(DataBase.java:25)
at tushu.BookManage.searchBook(BookManage.java:404)
java.lang.NullPointerException
at tushu.BookManage.searchBook(BookManage.java:406)