执行以下代码,直到 String check = "select * from borrow where librarycardnumber = ?"; 在单击鼠标后的 try{} catch{} 块中,然后在控制台中停止而没有任何错误。可能是什么问题?是错误的准备语句还是其他?谢谢你。
import javax.swing.*;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import java.awt.event.MouseAdapter;
import javax.swing.JTextField;
import java.awt.event.MouseEvent;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class libaryCard extends JFrame{
public JLabel lclabel;
public JTextField lcfield;
public JButton lcbutton;
public libaryCard(){
super("Library Card Check");
setLayout(new FlowLayout());
setSize(300, 130);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lclabel = new JLabel("Enter your Library Card Number:");
add(lclabel);
lcfield = new JTextField(20);
add(lcfield);
lcbutton = new JButton("Check");
add(lcbutton);
lcbutton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("mouse clicked");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+libaryCheck.DBname+"", "root", libaryCheck.DBpass);
System.out.println("Connected ");
String LB = lcfield.getText();
PreparedStatement stmt= null;
ResultSet libCheck = null;
String check = "select * from borrow where librarycardnumber = ?";
System.out.print("String executed");
stmt=conn.prepareStatement(check);
stmt.setString(1, LB);
libCheck = stmt.executeQuery(check);
System.out.println("Query executed");
if(libCheck.next()) {
String number = libCheck.getString("libraryCardNumber");
ISBNcheck isbn= new ISBNcheck();
isbn.setVisible(true);
System.out.println("mouse action complete");
}
else {
JOptionPane.showInputDialog("Card Number not found!");
}
} catch (Exception ed){
}
}
});
}
}