📄 null.java
字号:
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
public class NULL extends JFrame implements ActionListener
{
JTextField tfde=new JTextField();
JLabel ib=new JLabel("请输入学号:");
JLabel no=new JLabel("学号:");
JLabel n=new JLabel("姓名:");
JLabel s=new JLabel("性别:");
JLabel a=new JLabel("年龄:");
JLabel d=new JLabel("系别:");
JTextField no1=new JTextField();
//JTextField n1=new JTextField();
//JTextField s1=new JTextField();
//JTextField a1=new JTextField();
//JTextField d1=new JTextField();
JTextArea ttt=new JTextArea();
JLabel bb=new JLabel("学生选课系统");
JButton b=new JButton("查询");
JTextField ta1=new JTextField();
JTextField tfde2=new JTextField();
JLabel ib2=new JLabel("请输入要选择的课程号:");
JButton b2=new JButton("确定");
JLabel ib3=new JLabel("你可以选择的课程:");
JTextArea ta2=new JTextArea();
JTextArea ta3=new JTextArea();
public NULL()
{
super("学生选课系统查询组件");
setSize(800,460);
getContentPane().setLayout(null);
getContentPane().add(bb);
bb.setBounds(320,20,140,50);
getContentPane().add(ib);
ib.setBounds(10,80,120,20);
getContentPane().add(tfde);
tfde.setBounds(130,80,160,20);
getContentPane().add(b);
b.setBounds(310,80,70,20);
getContentPane().add(no);
no.setBounds(10,110,40,20);
//getContentPane().add(no1);
//no1.setBounds(40,110,60,20);
getContentPane().add(n);
n.setBounds(90,110,50,20);
//getContentPane().add(n1);
//n1.setBounds(130,110,40,20);
getContentPane().add(s);
s.setBounds(150,110,50,20);
//getContentPane().add(s1);
//s1.setBounds(200,110,40,20);
getContentPane().add(a);
a.setBounds(220,110,50,20);
//getContentPane().add(a1);
//a1.setBounds(270,110,40,20);
getContentPane().add(d);
d.setBounds(280,110,50,20);
//getContentPane().add(d1);
//d1.setBounds(340,110,40,20);
getContentPane().add(ttt);
ttt.setBounds(10,140,370,30);
getContentPane().add(ib2);
ib2.setBounds(10,180,150,20);
getContentPane().add(ta1);
ta1.setBounds(190,180,100,20);
getContentPane().add(b2);
b2.setBounds(305,180,72,20);
getContentPane().add(ta2);
ta2.setBounds(10,220,345,150);
getContentPane().add(ib3);
ib3.setBounds(390,80,120,40);
getContentPane().add(ta3);
ta3.setBounds(390,130,380,240);
b.addActionListener(this);
b2.addActionListener(this);
}
public static void main(String[] args)
{
NULL s=new NULL();
s.show();
}
public void getrecord(String sno) throws SQLException
{
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex)
{
ttt.setText(ex.getMessage());
System.exit(-1);
}
try
{
String url="jdbc:odbc:stuu";
String user="sa";
String password="";
con=DriverManager.getConnection(url,user,password);
//String SQLsc="SELECT * FROM sc ";
String SQL="SELECT * FROM student"+ " where sno=? ";
//Statement s =con.createStatement();
PreparedStatement p=con.prepareStatement(SQL);
p.setString(1,sno);
ResultSet rs=p.executeQuery();
//ResultSet rs1=s.executeQuery(SQLsc);
ttt.setText("");
while(rs.next())
{
ttt.append(rs.getString("sno")+" ");
ttt.append(rs.getString("sname")+" ");
ttt.append(rs.getString("ssex")+" ");
ttt.append(rs.getString("sage")+" ");
ttt.append(rs.getString("sdep")+"\n");
}
/* while(rs1.next())
{
ta3.append(rs1.getString("cno")+" ");
ta3.append(rs1.getString("cname")+" ");
ta3.append(rs1.getString("cc")+" ");
ta3.append(rs1.getString("ca")+" ");
}*/
rs.close();
//rs1.close();
p.close();
//s.close();
}catch(SQLException ex)
{
ttt.setText(ex.getMessage());
}
finally
{
con.close();
}
}
public void getrecord11() throws SQLException
{
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex)
{
ta3.setText(ex.getMessage());
System.exit(-1);
}
try
{
String url="jdbc:odbc:stuu";
String user="sa";
String password="";
con=DriverManager.getConnection(url,user,password);
String SQL="SELECT * FROM sc";
Statement s =con.createStatement();
//PreparedStatement p=con.prepareStatement(SQL);
//p.setString(1,sno);
ResultSet rs=s.executeQuery(SQL);
//ResultSet rs1=s.executeQuery(SQLsc);
//tfde.setText("");
while(rs.next())
{
ta3.append(rs.getString("cno")+" ");
ta3.append(rs.getString("cname")+" ");
ta3.append(rs.getString("cc")+" ");
ta3.append(rs.getString("ca")+" " + "\n");
}
rs.close();
//rs1.close();
//p.close();
s.close();
}catch(SQLException ex)
{
ta3.setText(ex.getMessage());
}
finally
{
con.close();
}
}
public void getrecord1(String cno) throws SQLException
{
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex)
{
ta2.setText(ex.getMessage());
System.exit(-1);
}
try
{
String url="jdbc:odbc:stuu";
String user="sa";
String password="";
con=DriverManager.getConnection(url,user,password);
String SQL="SELECT * FROM sc " + " where cno=? ";
PreparedStatement p=con.prepareStatement(SQL);
p.setString(1,cno);
ResultSet rs=p.executeQuery();
ta1.setText("");
while(rs.next())
{
ta2.append(rs.getString("cno")+" ");
ta2.append(rs.getString("cname")+" ");
ta2.append(rs.getString("cc")+" ");
ta2.append(rs.getString("ca")+" " + "\n");
}
rs.close();
p.close();
}catch(SQLException ex)
{
ta2.setText(ex.getMessage());
}
finally
{
con.close();
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b)
{
String ss=tfde.getText();
try
{
getrecord(ss);
}catch(SQLException ex)
{
ttt.setText(ex.getMessage());
}
}
else if (e.getSource()==b2)
{
String ss1=ta1.getText();
try
{
getrecord1(ss1);
}catch(SQLException ex)
{
ta2.setText(ex.getMessage());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -