在使用eclipse创建窗口时一直报错
package denglu;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Dao {
private String user="root";
private String password="111111";
private String url="jdbc:mysql://localhost:3306/gyc";
private Connection conn=null;
public Connection getConnection() {
try {
Class.forName( "com.mysql.jdbc.jc.driver");
} catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn=DriverManager.getConnection(url,user,password);
}catch (SQLException e){
e.printStackTrace();
}
return conn;
}
}
```java
package denglu;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
public class zy {
private JFrame frame;
private JTextField userTextField;
private JPasswordField passwordField;
private JLabel userLabel,passwordLabel;
private JButton loginButton,exitButton,resetButton;
private JPanel userPanel,passwordPanel,buttonPanel;
public void lunchFrame()
{
this.frame=new JFrame("登录窗口");
this.userTextField=new JTextField(12);
this.passwordField=new JPasswordField(12);
this.userLabel=new JLabel("用户名:");
this.passwordLabel=new JLabel("密 码:");
this.loginButton=new JButton("登录");
this.resetButton=new JButton("重置");
this .exitButton=new JButton("退出");
this.exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
this.userPanel= new JPanel();
this.passwordPanel=new JPanel();
this.buttonPanel=new JPanel();
this.userPanel.add(this.userLabel);
this.userPanel.add(this.userTextField);
this.passwordPanel.add(this.passwordLabel);
this.passwordPanel.add(this.passwordField);
this.buttonPanel.add(this.loginButton);
this.buttonPanel.add(this.resetButton);
this.buttonPanel.add(this.exitButton);
GridLayout gridLayout=new GridLayout(0,1);
frame.setLayout(gridLayout);
frame.add(this.userPanel);
frame.add(this.passwordPanel);
frame.add(this.buttonPanel);
frame.setSize(280,180);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Monitor monitor=new Monitor();
this.loginButton.addActionListener(monitor);
Monitor2 monitor2=new Monitor2();
this.resetButton.addActionListener(monitor2);
}
public static void main(String[] args) {
zy window=new zy ();
window.lunchFrame();
}
class Monitor implements ActionListener
{
private Connection conn=null;
private PreparedStatement preparedStatement=null;
private ResultSet resultSet=null;
@Override
public void actionPerformed(ActionEvent e) {
//TODO Auto-generated method stub
String name=userTextField.getText();
char[] ch=passwordField.getPassword();
String password=new String(ch);
conn=new Dao().getConnection();
String sql="select * from user where user=? and password=?";
try {
preparedStatement=conn.prepareStatement(sql);
preparedStatement.setString(1,name);
preparedStatement.setString(2,password);
resultSet=preparedStatement.executeQuery();
if(resultSet.next())
{
JOptionPane.showMessageDialog(null, "欢迎使用本系统");
}
else
{
JOptionPane.showMessageDialog(null,"用户名或密码错误,请重新登录!");
}
}catch(SQLException e1) {
//TODO Auto-generated catch block
e1.printStackTrace();
}finally
{
if(resultSet!=null)
{
try {
resultSet.close();
}catch (SQLException e1) {
//TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(preparedStatement!=null)
{
try {
preparedStatement.close();
}catch (SQLException e1) {
//TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(conn!=null)
{
try {
conn.close();
}catch (SQLException e1){
//TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
class Monitor2 implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
userTextField.setText("");
passwordField.setText("");
}
}
}
###### 运行结果及详细报错内容

###### 我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
网上搜索是jdk版本低了,然后重新下载了也不行
缺少com.mysql.jdbc.jc.driver 这个包,这个包是mysql驱动包,你得去下载个驱动包导入项目。
但是吧,我看你工程里又有驱动包
你可以试着清除缓存,重新编译试试。如果不行,我估计你导入的包位置可能不对。
驱动名 写错了 是 com.mysql.cj.jdbc.Driver
由于没有具体的报错信息或代码,我无法有效地解决该问题,请提供更具体的信息。
这里看看jar包有没有加进项目中