大多数解决方案都说要添加连接器jar文件。但即使在libraries文件夹中这样做了,我仍然会得到classnotfoundexception。代码如下所示。
package javaapplication2;
import javax.swing.JOptionPane;
import java.sql.*;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String name = jTextField1.getText();
String email = jTextField2.getText();
String Gender = " ";
String Android = " ";
if (jRadioButton1.isSelected())
Gender = "Male";
else if (jRadioButton2.isSelected())
Gender = "Female";
String lang = jComboBox1.getSelectedItem().toString();
if (jCheckBox1.isSelected())
Android = "With Android";
else if (jCheckBox2.isSelected())
Android = "Without Android";
//JOptionPane.showMessageDialog(this, "Successfully Registered");
try {
Class.forName("com.jdbc.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "");
PreparedStatement ps = con.prepareStatement("insert into user values(?,?,?,?,?))");
ps.setString(1, name);
ps.setString(2, Gender);
ps.setString(3, email);
ps.setString(4, lang);
ps.setString(5, Android);
ps.executeUpdate();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e);
}
}
在上面的两张图片中,您可以看到我添加了连接器文件并在服务中创建了连接,但在运行该文件时仍然会出现错误。请帮我解决它。我是个初学者,我已经试了好几个小时了。
暂无答案!
目前还没有任何答案,快来回答吧!