2013-12-16 68 views
-2

我想從數據庫(bill_number)獲取最大值並將其設置爲jtextfield。但我得到錯誤(void類型不允許在這裏)。從數據庫中獲取最大值並設置爲jtextfield

哪裏是問題,我的代碼

public void number(){ 
try{ 
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    Connection cn = DriverManager.getConnection("Jdbc:Odbc:ds_comboPractice"); 
    String sql = "select count(Bill_Number)=? from combopractice"; 
    PreparedStatement pst = cn.prepareStatement(sql); 
    pst.setString(1, txt4.setText(sql)); 
    pst.executeQuery(); 
    cn.close(); 

} 
catch(ClassNotFoundException ex){ 
    JOptionPane.showMessageDialog(this, "Class not found"); 
    } 
} 

回答

1

你需要做的txt4.getTextsetText

然後你想你的executeQuery的結果分配給ResultSet和讀取從結果。

0
pst.setString(1, txt4.setText(sql)); 

setText()回報void

你需要一個字符串參數

相關問題