亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在java中的另一個函數中使用帶有參數的函數

如何在java中的另一個函數中使用帶有參數的函數

瀟瀟雨雨 2022-11-02 16:55:18
如何在另一個函數中使用帶有參數的函數,并在代碼 java 中的條件 sql 中使用它,如下所示:query = "update date set date_fin = '"+dates+"' where id ='"+getid()+"'";下面是我的 Java 代碼。我有兩個功能;如何在函數getid中使用函數updateDatefin?// get id of line datepublic int getid(String date){    String datedb;    datedb = date;    int h = 0;    try{       Connection con=ConnectDB();       Statement stmt=con.createStatement();       ResultSet rs=stmt.executeQuery("select id  from date where date_debut = '"+datedb+"' ");       while(rs.next()) {           h =rs.getInt("id");       }    } catch (SQLException | IOException ex) {        Logger.getLogger(Recognizer.class.getName()).log(Level.SEVERE, null, ex);    }    return h;}//date time insertionpublic void updateDatefin(String date_fin){    String dates = null;    dates = date_fin;    try{          Connection conn=ConnectDB();        String query;        query = "update date set date_fin = '"+dates+"' where id ='"+getid()+"'";        // create the mysql insert preparedstatement        PreparedStatement preparedStmt = conn.prepareStatement(query);        // execute the preparedstatement        preparedStmt.execute();        //JOptionPane.showMessageDialog(null, "Data added");    }catch(SQLException | HeadlessException e){        System.out.println("errrr");    }catch(IOException iox){    }           }
查看完整描述

3 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

您只需將要使用的值發送到函數:

query = "update date set date_fin = '" + dates + "' where id ='" + getid(date_fin) + "'";

如果這不是您想要的值,只需date_fin在此行中替換為您需要的參數即可。



查看完整回答
反對 回復 2022-11-02
?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

對于這種情況,您可以通過兩種方式調用函數:

  1. 只需創建一個新變量并調用函數并將該變量傳遞給查詢。

字符串 getID=getid(date_fin);

字符串查詢;

query = "更新日期集 date_fin = '"+dates+"' where id ='"+getID+"'";

  1. 在查詢中直接調用函數

字符串查詢;

query = "更新日期集 date_fin = '"+dates+"' where id ='"+getid(date_fin)+"'";

注意:您必須在 getid 函數中傳遞一個參數。


查看完整回答
反對 回復 2022-11-02
?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

你可以試試這個:


  query = "update date set date_fin = ? where id = ?";

  // create the mysql insert preparedstatement

  PreparedStatement preparedStmt = conn.prepareStatement(query);

  preparedStmt.setString(1, dates);

  preparedStmt.setString(2, getid(date_fin));

  // execute the preparedstatement

  preparedStmt.execute();


查看完整回答
反對 回復 2022-11-02
  • 3 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號