当前位置: 代码迷 >> J2SE >> 急请教怎么进行循环插入数据库呀
  详细解决方案

急请教怎么进行循环插入数据库呀

热度:44   发布时间:2016-04-24 13:59:29.0
急!!!请问如何进行循环插入数据库呀!
while(rs5.next())
{
String   id=rs5.getString( "id ");   //(NOT   NULL)
String   unitid=rs5.getString( "unitid ");
if(unitid==null)
      unitid= " ";
String   unitname=rs5.getString( "unitname ");
if(unitname==null)
      unitname= " ";
String   name=rs5.getString( "name ");
if(name==null)
      name= " ";
String   sex=rs5.getString( "sex ");
if(sex==null)
      sex= " ";
String   folkcode=rs5.getString( "folkcode ");
if(folkcode==null)
      folkcode= " ";
String   birth=rs5.getString( "birth ");
if(birth==null)
      birth= " ";
String   personcode=rs5.getString( "personcode ");
if(personcode==null)
      personcode= " ";
String   duty=rs5.getString( "duty ");
if(duty==null)
      duty= " ";
String   politycode=rs5.getString( "politycode ");
if(politycode==null)
      politycode= " ";
String   degreecode=rs5.getString( "degreecode ");
if(degreecode==null)
      degreecode= " ";
String   post=rs5.getString( "post ");
if(post==null)
      post= " ";
String   workcode=rs5.getString( "workcode ");
if(workcode==null)
      workcode= " ";
String   officetel=rs5.getString( "officetel ");
if(officetel==null)
      officetel= " ";
String   hometel=rs5.getString( "hometel ");
if(hometel==null)
    hometel= " ";
String   movetel=rs5.getString( "movetel ");
if(movetel==null)
      movetel= " ";
String   notes=rs5.getString( "notes ");
if(notes==null)
      notes= " ";
conn5.close();
String   sql= "insert   into   sec_bwglry   (id,unitid,unitname,name,sex,folkcode,birth,personcode,duty,politycode,degreecode,post,workcode,officetel,hometel,movetel,notes) "+ "values( ' "+bwglid+ " ', ' "+unitid+ " ', ' "+unitname+ " ', ' "+name+ " ', ' "+sex+ " ', ' "+folkcode+ " ', ' "+birth+ " ', ' "+personcode+ " ', ' "+duty+ " ', ' "+politycode+ " ', ' "+degreecode+ " ', ' "+post+ " ', ' "+workcode+ " ', ' "+officetel+ " ', ' "+hometel+ " ', ' "+movetel+ " ', ' "+notes+ " ') ";
try
{
Connection   conn=   DriverManager.getConnection(url,user,password);
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt2.executeUpdate(tmp2);
conn2.close();
}
catch(SQLException   e)
{
out.print( "SQL异常! ");
}
用这样的处理后,只能向数据库了增加一条记录!!
谢谢,给出具体点的说明!

------解决方案--------------------
public int insertT_KSLKYTHND(ShowDetaileEntDAOData data) throws DAOException {
if (log.isTraceEnabled()) {
log.trace( "entering ShowDetaileEntDAO.insertT_KSLKYTHND() ");
}
  相关解决方案