classnotfound错误,即使在将mysql连接器jar文件添加到我的项目的netbeans中的libraries文件夹之后也是如此

vnzz0bqm  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(178)

大多数解决方案都说要添加连接器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);
            }
        }



在上面的两张图片中,您可以看到我添加了连接器文件并在服务中创建了连接,但在运行该文件时仍然会出现错误。请帮我解决它。我是个初学者,我已经试了好几个小时了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题