问题Exceptioninthread"main"java.lang.NoSuchMethodError:mainPressandkeytocontinue..代码是importjava.sql.*;publicclassSqlCon{privateConnectionconn=null;publicConnectiongetc...
问题
Exception in thread "main" java.lang.NoSuchMethodError:main Press and key to continue..
代码是
import java.sql.*;
public class SqlCon {
private Connection conn=null;
public Connection getconnection(){
String sql1="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sql2="jdbc:microsoft:sqlserver://localhost:1433;databasename=Admin";
try {
Class.forName(sql1);
conn=DriverManager.getConnection(sql2, "sa", "123");
} catch (Exception e)
{
System.out.println("OK");
e.printStackTrace();
}
return conn;
}
}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import java.sql.*;
public class Loginframe extends JFrame implements ActionListener{
JLabel lable1=new JLabel("管理员账号:");
JLabel lable2=new JLabel("管理员密码:");
JTextField text1=new JTextField(15);
JTextField text2=new JTextField(15);
JButton bt1=new JButton("登陆");
JButton bt2=new JButton("取消");
public Loginframe() {
this.setTitle("管理员登陆窗体");
this.setBounds(200, 200, 260, 140);
this.setLayout(new GridLayout(3,1));
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
bt1.addActionListener(this);
bt2.addActionListener(this);
jp1.add(lable1);
jp1.add(text1);
jp2.add(lable2);
jp2.add(text2);
jp3.add(bt1);
jp3.add(bt2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ex) {
if(ex.getActionCommand().equals("登陆")) {
String name=text1.getText();
String password=text2.getText();
SqlCon sc = new SqlCon();
Connection conn=sc.getconnection();
PreparedStatement stmt=null;
ResultSet rs=null;
String sql="select * from admin where ADname=? and ADpwd=?";
try {
stmt=conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.setString(2, password);
rs=stmt.executeQuery();
if(rs.next()){ //判断数据集中是否有数据,有则表明当前输入的用户和密码存在
this.setVisible(false);
new DataFrame();
}
else{
JOptionPane.showMessageDialog(null, "用户名或密码错误!!");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
if(ex.getSource()==bt2) {
System.exit(0);
}
}
public static void main(String[] args) {
new Loginframe();
}
}
展开