package per1;
import java.awt.*;import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.*;
public class Cland extends JFrame implements ActionListener{
/**
*
*/
JLabel jl1,jl2;
JTextField jtf1;
JPasswordField jpw1;
JPanel jp1,jp2,jp3,jp4;
JButton jb1,jb2;
JRadioButton jrb1,jrb2,jrb3;
ButtonGroup bg;
public static void main(String []args)
{
Cland cl=new Cland();
}
public Cland()
{
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jl1=new JLabel("用户名:");
jl2=new JLabel("密 码:");
jtf1=new JTextField(10);
jpw1=new JPasswordField(10);
jb1=new JButton("登陆");
jb1.addActionListener(this);
jb2=new JButton("注销");
jrb1=new JRadioButton("管理员");
jrb2=new JRadioButton("老师");
jrb3=new JRadioButton("学生");
ButtonGroup bg=new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
bg.add(jrb3);
this.setLayout(new GridLayout(4,1));
jp1.add(jl1);
jp1.add(jtf1);
jp2.add(jl2);
jp2.add(jpw1);
jp3.add(jrb1);
jp3.add(jrb2);
jp3.add(jrb3);
jp4.add(jb1);
jp4.add(jb2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.setTitle("学生成绩管理系统");
this.setSize(300,150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1)
{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
String []a=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:per","sa","sa");
ps=conn.prepareStatement("select * from user1 where 用户名=? and 密码=?");
ps.setString(1, jtf1.getText());
ps.setString(2, new String(jpw1.getPassword()));
rs=ps.executeQuery();
while(rs.next())
{
if (rs.getString(3)=="管理员")
{
Tsel re=new Tsel();
this.dispose();
}
}
}catch(Exception e1)
{
e1.printStackTrace();
}finally
{
try{
if(rs!=null)
{
rs.close();
}
if(ps!=null)ps.close();
if(conn!=null)conn.close();
}catch(Exception e2)
{
e2.printStackTrace();
}
}
}
}}
import java.awt.*;import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;import javax.swing.*;
public class Cland extends JFrame implements ActionListener{
/**
*
*/
JLabel jl1,jl2;
JTextField jtf1;
JPasswordField jpw1;
JPanel jp1,jp2,jp3,jp4;
JButton jb1,jb2;
JRadioButton jrb1,jrb2,jrb3;
ButtonGroup bg;
public static void main(String []args)
{
Cland cl=new Cland();
}
public Cland()
{
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp4=new JPanel();
jl1=new JLabel("用户名:");
jl2=new JLabel("密 码:");
jtf1=new JTextField(10);
jpw1=new JPasswordField(10);
jb1=new JButton("登陆");
jb1.addActionListener(this);
jb2=new JButton("注销");
jrb1=new JRadioButton("管理员");
jrb2=new JRadioButton("老师");
jrb3=new JRadioButton("学生");
ButtonGroup bg=new ButtonGroup();
bg.add(jrb1);
bg.add(jrb2);
bg.add(jrb3);
this.setLayout(new GridLayout(4,1));
jp1.add(jl1);
jp1.add(jtf1);
jp2.add(jl2);
jp2.add(jpw1);
jp3.add(jrb1);
jp3.add(jrb2);
jp3.add(jrb3);
jp4.add(jb1);
jp4.add(jb2);
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.setTitle("学生成绩管理系统");
this.setSize(300,150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1)
{
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
String []a=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:per","sa","sa");
ps=conn.prepareStatement("select * from user1 where 用户名=? and 密码=?");
ps.setString(1, jtf1.getText());
ps.setString(2, new String(jpw1.getPassword()));
rs=ps.executeQuery();
while(rs.next())
{
if (rs.getString(3)=="管理员")
{
Tsel re=new Tsel();
this.dispose();
}
}
}catch(Exception e1)
{
e1.printStackTrace();
}finally
{
try{
if(rs!=null)
{
rs.close();
}
if(ps!=null)ps.close();
if(conn!=null)conn.close();
}catch(Exception e2)
{
e2.printStackTrace();
}
}
}
}}
解决方案 »
- 这个程序哪里错了
- 一个测网络延迟和带宽的程序,发10M的数据有问题
- 请教:java中如何将1970年以来的秒数转化为日期时间个
- jsp的文件上传-------access
- 从来没有用过中文为包名的,今天测试在类中取得当前文件所在的相对路径与绝对路径时发现个这个问题,特此提醒一下,有谁设置包名为中文的
- 请问PreparedStatementWrapper的用法和作用?
- JPanel,JFrame 设置背景图片???
- UltraEdit 能不能直接调用编译器?
- ★★★★★我的开源、免费软件★★★★★
- 求各位指导一个比较奇怪的问题
- java 向文件的首行追加一条数据
- 关于截取数据的问题,在线等,谢谢!
rs.getString(3).equals("管理员")
楼上正解!