如何在另一个函数中使用带有参数的函数,并在代码 java 中的条件 sql 中使用它,如下所示:
query = "update date set date_fin = '"+dates+"' where id ='"+getid()+"'";
下面是我的 Java 代码。我有两个功能;如何在函数getid中使用函数updateDatefin?
// get id of line date
public 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 insertion
public 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){
}
}
斯蒂芬大帝
神不在的星期二
jeck猫
相关分类