📄 find.java
字号:
/*货物管理程序设计
设计者:李爽
版次:1.0**/
package com.hesj.mod;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Find extends JFrame implements ActionListener,WindowListener{
/* public static void main(String args[]){
Find frame=new Find();
}*/
JLabel lb1;
JTextField tf1;
JButton bu1;
JTextArea ta1;
Connection con1;//设定连接数据库的对象
ResultSet rs1;
Statement st1;
String str1="";
String str2="";
//构造函数
public Find(){
super("Find");
addWindowListener(this);
Container c=getContentPane();
c.setLayout(null);
lb1=new JLabel("要查询的商品:");
lb1.setSize(120,20);
lb1.setLocation(10,20);
c.add(lb1);
tf1=new JTextField();
tf1.setSize(120,20);
tf1.setLocation(130,20);
c.add(tf1);
bu1=new JButton("查询");
bu1.setSize(60,20);
bu1.setLocation(360,20);
bu1.addActionListener(this);
c.add(bu1);
ta1=new JTextArea();
ta1.setSize(420,280);
ta1.setLocation(20,50);
c.add(ta1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500,400);
setVisible(true);
connect_db();
}
//加载JDBC驱动程序
public void connect_db(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e1){System.out.println("驱动器无法找到!!");}
try{
con1=DriverManager.getConnection("jdbc:odbc:Gooddb");
st1=con1.createStatement();
}catch(SQLException e2){System.out.println("无法找到表!!");}
}
//关闭数据库
public void close_db(){
try{
st1.close();
con1.close();
}catch(SQLException e2){System.out.println("关闭数据库失败!!");}
}
//事件处理方法
public void actionPerformed(ActionEvent e){
String str1;
String str2;
String std_id;
try
{
str2=tf1.getText();
rs1=st1.executeQuery("select Good_ID,Good_name,Good_price,Good_amt from Tbl_Good where Good_name='" +str2+ "'");
str1="";
while(rs1.next()){
str1=str1+rs1.getLong("Good_ID")+"\t"+rs1.getString("Good_name")+"\t"+rs1.getLong("Good_price")+"\t"+rs1.getLong("Good_amt")+"\n";
}
ta1.setText(str1);
}catch(SQLException e2){System.out.println("查询失败!!");}
}
//窗口处理方法
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowClosing(WindowEvent e){
close_db();
System.exit(1);
}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -