Thu Jan 31, 2013 11:19 pm
package connectingdatabase.Search;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
/**
*
* @author sami
*/
public class BookSearch extends JDialog {
/**
* Creates a new instance of VisitorPanel
*/
public BookSearch(Connection connection, JFrame myMother) {
super(myMother, "Search Book", true);
this.connection = connection;
MetaData = new MyComboBox(connection, "Book");
setSize(400, 300);
setLocation(100, 100);
Search.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DoSearch();
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
hide();
}
});
setLayout(new FlowLayout());
forma.setBorder(new TitledBorder(new LineBorder(Color.GRAY, 2), "Search panel"));
forma.setSize(400, 100);
forma.setLocation(10, 30);
forma.setLayout(new GridLayout(2, 2));
forma.add(MetaData);
forma.add(Search);
forma.add(SearchLabel);
forma.add(SearchFiled);
add(forma);
add(cancel);
}
public void DoSearch() {
String Col = (String) MetaData.getSelectedItem();
String Value = SearchFiled.getText();
mySearchResult showrs;
String query = "Select * from Book where " + Col + " Like('%" + Value + "%');";
try {
Statement stat = connection.createStatement();
rs = stat.executeQuery(query);
showrs = new mySearchResult(rs, this);
showrs.show();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private Connection connection;
private JTextField SearchFiled = new JTextField(20);
private MyComboBox MetaData;
private JLabel SearchLabel = new JLabel("Search :");
private JPanel forma = new JPanel();
private JButton Search = new JButton("Search");
private JButton cancel = new JButton("Cancel");
private ResultSet rs;
}
|
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.