-
November 10th, 2013, 02:16 AM
#1
Event Based Query
When I use the commented out query to query the database,
there were something to return, when I used the method below,
The JTable was filled with nothing, why?
Thanks
Jack
Code:
public class SalesSC extends JDialog {
Database db;
JLabel lblSearch = new JLabel("Search Criteria:");
protected JTextField txtSearch = new JTextField(50);
JTable tblRes = new JTable();
JScrollPane sp = new JScrollPane();
SalesSC self;
public SalesSC(Database _db) {
db = _db;
self = this;
initComponents();
}
private void initComponents() {
this.setSize(new Dimension(300,300));
this.setLocationRelativeTo(null);
this.setLayout(new MigLayout());
this.add(lblSearch);
this.add(txtSearch, "wrap");
sp.add(tblRes);
this.add(sp);
txtSearch.addKeyListener(new KeyListener(){
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
String str = txtSearch.getText().trim();
try {
ResultSet rs = db.searchCustomerTable(str);
/*String sql = "select c.CustomerCode AS '顾客ID' , c.LastName || ' ' || c.FirstName AS '名字', c.MobilePhoneNumber AS '手机号', "
+ "IFNULL(sum(IFNULL(od.NetSales,0)),0) AS '总销售额' from "
+ " customer c LEFT JOIN orders o ON (c.CustomerCode = o.CustomerCode) "
+ " LEFT JOIN order_details od ON (o.OrderCode = od.OrderCode) "
+ " where c.FirstName like '%188%' OR c.LastName like '%188%' OR "
+ " c.MobilePhoneNumber Like '%188%' OR c.FirstName || ' ' || c.LastName Like '%188%' "
+ " OR c.FirstName || c.LastName Like '%188%' OR c.CustomerCode Like '%188%' group by 顾客ID "
+ " order by c.CustomerCreationDate DESC";*/
//ResultSet rs = db.query(sql);
if (!rs.isBeforeFirst())
{
System.out.println("Found");
}
else
{
System.out.println("Nothing Found");
}
tblRes.setModel(DbUtils.resultSetToTableModel(rs));
self.revalidate();
self.repaint();
tblRes.revalidate();
tblRes.repaint();
} catch (SQLException ex) {
Logger.getLogger(SalesSC.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
}
-
November 11th, 2013, 05:16 PM
#2
Re: Event Based Query
And the searchCustomerTable(str) is a java built in function...?
-------------------------------------------
ResultSet rs = db.searchCustomerTable(str);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|