1. 程式人生 > >jdbc增加資料返回自動編號

jdbc增加資料返回自動編號

public String addEcms(String tableName,String files,String fileVale)
 {
  try {
   String sqll = "insert into "+tableName+"("+files+")values("+encod.ChineseToUnicode(fileVale)+")";
   st = conn.createStatement();
   
   st.execute(sqll,Statement.RETURN_GENERATED_KEYS);
 
   rs = st.getGeneratedKeys(); 
   if(rs.next())
    return String.valueOf(rs.getInt(1));
   else
    return null;
  } catch (Exception e) {
   e.printStackTrace();
   return null;
  
  }finally
  {
   this.close();
  }
 }