我有一张这样的表:
ARITHMOS KOD DATE A B C
1 ΑΓΟ 01/08/2016 5 2 3
2 ΠΛΗ 02/08/2016 3 2 1
AND netbeans程序我想插入名称表和DATE AND KOD,只获得符合条件的行。
代码:
String pote=ac3.getText();//name table
String c=((JTextField)jdt1.getDateEditor().getUiComponent()).getText();//date
String d=((JTextField)jdt2.getDateEditor().getUiComponent()).getText();//date
String s0=(String)jcb1.getSelectedItem();//KOD
String sql="SELECT * FROM "+pote+" WHERE (Hmerominia BETWEEN "+c+" AND "+d+") AND KOD='"+s0+"' ORDER BY ARITHMOS";
if(re == JOptionPane.YES_OPTION){ 尝试{
stm=(OracleStatement) conn.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_UPDATABLE);
rs = (OracleResultSet) stm.executeQuery(sql);
UpdateJTable();
/* while(rs.next()){
v0.setText(rs.getString("ARITHMOS"));
}*/
}
catch(Exception e1){
JOptionPane.showMessageDialog(null, e1);
}
}else if (re == JOptionPane.NO_OPTION) {
this.setVisible(true);
}
显示无效号码时出错。
答案 0 :(得分:0)
修正:
public static ResultSet Consult(String consult){
Connection conn = ConnectDB();//connection to database
Statement declare;
try{
declare=conn.createStatement();
ResultSet rs=declare.executeQuery(consult);
return rs;
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
return null;
}
}
Code in Button:
String pote=ac3.getText();//chosen table name
String c=((JTextField)jdt1.getDateEditor().getUiComponent()).getText();//date as varchar2 set to database table
String d=((JTextField)jdt2.getDateEditor().getUiComponent()).getText();//date as varchar2 set to database table
String s0=(String)jcb1.getSelectedItem();//chosen item
String sql="SELECT * FROM "+pote+" WHERE Hmerominia BETWEEN '"+c+"' AND '"+d+"' AND KOD='"+s0+"'";
int re = JOptionPane.showConfirmDialog(this, "SEARCH?", "Confirm",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (re == JOptionPane.YES_OPTION) {
DefaultTableModel md=( DefaultTableModel)pel300.getModel();
md.setRowCount(0);
rs=(OracleResultSet) Connect.Consult(sql);//Connect class
try{
while(rs.next()){
Vector v=new Vector();
v.add(rs.getString(1));
v.add(rs.getString(2));
v.add(rs.getString(3));
v.add(rs.getString(4));
v.add(rs.getString(5));
v.add(rs.getString(6));
v.add(rs.getString(7));
v.add(rs.getString(8));
md.addRow(v);
pel300.setModel(md);
pel300.setShowGrid(true);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}else if (re == JOptionPane.NO_OPTION) {
this.setVisible(true);
}