当前位置: 技术问答>java相关
SQL语句问题-->怎么在一个try..catch里执行多条SQL语句啊?
来源: 互联网 发布时间:2017-04-14
本文导语: 比如我有两条语句如下 Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz'); Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz'); SQLd="Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂...
比如我有两条语句如下
Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz');
Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
SQLd="Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz');Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');";
try { InstR = DBSQL.executeUpdate(SQLd)==true; }
catch (Exception e) { System.err.println("Err!Insert Classes-1:"+e.getMessage()); InstR=false;}
这样写就会出错呢~~是不是mySql不能解释“;”呢?
如果把两句分开来写,分别try...catch就可以的
但是我的SQL语句很多的话,不是要用很多try...catch啊~~怎么就只用一个try...catch呢?
Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz');
Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
SQLd="Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz');Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');";
try { InstR = DBSQL.executeUpdate(SQLd)==true; }
catch (Exception e) { System.err.println("Err!Insert Classes-1:"+e.getMessage()); InstR=false;}
这样写就会出错呢~~是不是mySql不能解释“;”呢?
如果把两句分开来写,分别try...catch就可以的
但是我的SQL语句很多的话,不是要用很多try...catch啊~~怎么就只用一个try...catch呢?
|
Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz');
Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
SQLd="Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz')";
try { InstR = DBSQL.executeUpdate(SQLd)==true;
SQLd = "Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
InstR = DBSQL.executeUpdate(SQLd)==true;
}
catch (Exception e) { System.err.println("Err!Insert Classes-1:"+e.getMessage()); InstR=false;}
Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
SQLd="Insert into Class (CId,CName,CFolder) values (1,'高中部同步课堂','gaoz')";
try { InstR = DBSQL.executeUpdate(SQLd)==true;
SQLd = "Insert into Class (CId,CName,CFolder) values (2,'初中部同步课堂','chuz');
InstR = DBSQL.executeUpdate(SQLd)==true;
}
catch (Exception e) { System.err.println("Err!Insert Classes-1:"+e.getMessage()); InstR=false;}
|
批处理