當前位置:成語大全網 - 新華字典 - java編寫的GUI 怎麽實現查找功能(使用搜索

java編寫的GUI 怎麽實現查找功能(使用搜索

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();

}

}

}