java编写的GUI 怎么实现查找功能(使用搜索
1个回答
2017-05-01 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
java编写的GUI 怎么实现查找功能:
package communitys.Connect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class dxdsy extends JFrame implements ActionListener{
private JButton button = new JButton("搜索");
private JTextField textfile = new JPasswordField("请输入文件名称······");
public dxdsy()
{
this.setLayout(null);
this.setBounds(200,200, 500,500);
textfile.setBounds(1, 1, 100,20);
button.setBounds(1, 25, 80,80);
this.add(button);
this.add(textfile);
button.addActionListener(this);//添加事件监听
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
String sql = "select * from tablename where 条件 like '%"+textfile.getText()+"%'";
try {
Class.forName("驱动字符");
Connection conn = DriverManager.getConnection("驱动字符");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sql);
//这个rs集合当中就是想要的数据
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
package communitys.Connect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class dxdsy extends JFrame implements ActionListener{
private JButton button = new JButton("搜索");
private JTextField textfile = new JPasswordField("请输入文件名称······");
public dxdsy()
{
this.setLayout(null);
this.setBounds(200,200, 500,500);
textfile.setBounds(1, 1, 100,20);
button.setBounds(1, 25, 80,80);
this.add(button);
this.add(textfile);
button.addActionListener(this);//添加事件监听
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
String sql = "select * from tablename where 条件 like '%"+textfile.getText()+"%'";
try {
Class.forName("驱动字符");
Connection conn = DriverManager.getConnection("驱动字符");
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sql);
//这个rs集合当中就是想要的数据
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询