JAVA图形界面与数据库SQL2005连接登入问题
packagevalidate;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax....
package validate;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class enter extends JFrame implements ActionListener{
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JLabel l1=new JLabel(" 用户名:");
JLabel l2=new JLabel(" 密 码:");
JLabel l3=new JLabel();
JTextField name=new JTextField(8);
JPasswordField pass=new JPasswordField(8);
JButton b1=new JButton("登录");
JButton b2=new JButton("退出");
public enter(){
super("校园卡信息管理系统");
b1.addActionListener(this);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
p1.setLayout(new GridLayout(2,2));
p2.setLayout(new FlowLayout());
p3.setLayout(new FlowLayout());
p4.setLayout(new GridLayout(3,1));
p4.add(p1);p4.add(p2);p4.add(p3);
this.getContentPane().add(p4);
p1.add(l1);p1.add(name);
p1.add(l2);p1.add(pass);
p2.add(b1);p2.add(b2);
p3.add(l3);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();}});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0); }});
setSize(300,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String a=String.valueOf(pass.getPassword());
try{
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://;serverName=081_JML09;DatabaseName=cardSystem;user=sa;password=sbs@SBS";
Connection con=DriverManager.getConnection(url);
Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();
rs=stmt.executeQuery("select * from account");
while(rs.next())
{
String na=rs.getString("username");
String pw=rs.getString("password");
if((na.equals("username")&&pw.equals("0password")))
}
public static void main(String[] args) {
new enter();
}
} 展开
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class enter extends JFrame implements ActionListener{
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JLabel l1=new JLabel(" 用户名:");
JLabel l2=new JLabel(" 密 码:");
JLabel l3=new JLabel();
JTextField name=new JTextField(8);
JPasswordField pass=new JPasswordField(8);
JButton b1=new JButton("登录");
JButton b2=new JButton("退出");
public enter(){
super("校园卡信息管理系统");
b1.addActionListener(this);
this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
p1.setLayout(new GridLayout(2,2));
p2.setLayout(new FlowLayout());
p3.setLayout(new FlowLayout());
p4.setLayout(new GridLayout(3,1));
p4.add(p1);p4.add(p2);p4.add(p3);
this.getContentPane().add(p4);
p1.add(l1);p1.add(name);
p1.add(l2);p1.add(pass);
p2.add(b1);p2.add(b2);
p3.add(l3);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();}});
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0); }});
setSize(300,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String a=String.valueOf(pass.getPassword());
try{
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://;serverName=081_JML09;DatabaseName=cardSystem;user=sa;password=sbs@SBS";
Connection con=DriverManager.getConnection(url);
Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();
rs=stmt.executeQuery("select * from account");
while(rs.next())
{
String na=rs.getString("username");
String pw=rs.getString("password");
if((na.equals("username")&&pw.equals("0password")))
}
public static void main(String[] args) {
new enter();
}
} 展开
2个回答
展开全部
url="jdbc:sqlserver://;serverName=081_JML09;DatabaseName=cardSystem;user=sa;password=sbs@SBS";
这句话有问题吧,连数据库服务器所在IP地址和端口都没有,改成:
url="jdbc:sqlserver://127.0.0.1:1433;serverName=081_JML09;DatabaseName=cardSystem;user=sa;password=sbs@SBS";
(假设数据库在本机127.0.0.1,端口为默认端口1433)
这句话有问题吧,连数据库服务器所在IP地址和端口都没有,改成:
url="jdbc:sqlserver://127.0.0.1:1433;serverName=081_JML09;DatabaseName=cardSystem;user=sa;password=sbs@SBS";
(假设数据库在本机127.0.0.1,端口为默认端口1433)
展开全部
你的连接方式有误,
1. Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;databaseName=pubs";
String sUsr="sa";
String sPwd="sbs@SBS"//你的SQL Server数据库sa登录的密码
Connection con=DriverManager.getConnection(url,sUsr,sPwd);
Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();
rs=stmt.executeQuery("select * from account");
2.你的jdbc数据库连接的Jar包,放在你项目的lib目录下
1. Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;databaseName=pubs";
String sUsr="sa";
String sPwd="sbs@SBS"//你的SQL Server数据库sa登录的密码
Connection con=DriverManager.getConnection(url,sUsr,sPwd);
Statement stmt=null;
ResultSet rs=null;
stmt=con.createStatement();
rs=stmt.executeQuery("select * from account");
2.你的jdbc数据库连接的Jar包,放在你项目的lib目录下
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询