数据库未在Java中更新

时间:2017-02-09 12:46:21

标签: java database sql-update

代码不想更新,并且在从组合框(getCurType)获取货币名称时表示存在空字符串。虽然它在println声明帖子中发布,但显示它从combobox获得正确的内容。

public void CurUpdate(){

     //*String str=currencyFrom.getSelectedItem().toString();
    //*String getRatesFrom= str.replaceAll("[^0-9.]", "");
    String str1=currencyTo.getSelectedItem().toString();
    String getRatesTo= str1.replaceAll("[^0-9.]", "");
    String getCurType=str1.replaceAll("[^a-zA-Z]", "");
    //*double ipa=Double.parseDouble(getRatesFrom);
    double opa=Double.parseDouble(getRatesTo);
    double ui=Double.parseDouble(inputAmount.getText());
    amountFrom=ui*opa;
    outputAmount.setText(""+amountFrom);
   double c=Double.valueOf(outputAmount.getText());
   //*String cc=String.valueOf(outputAmount.getText());
   System.out.println(""+c);
   System.out.println(getCurType);

    try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/currency","root","password");
        String sql="UPDATE logs SET res=res-? WHERE name=?";
        PreparedStatement pst=con.prepareStatement(sql);
        pst.setDouble(1,c);
        pst.setString(2,getCurType);
        int i=pst.executeUpdate();

       if(i>0){
        JOptionPane.showMessageDialog(this,"Table updated");

        }else{
         JOptionPane.showMessageDialog(this,"Can't update");
        }
     }catch(Exception e){}

}

0 个答案:

没有答案