您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java语言MySQL批处理_MySQL

2024/3/10 3:27:48发布22次查看
本质来讲就是使用statement和prestatement的addbatch()方法
代码
import java.sql.*;public class getconnection{ public static void main(string[] args){ access2database adb=new access2database(); connection conn=adb.getconn(); //transaction dealing preparedstatement pstam=null; try{ conn.setautocommit(false); string sql=insert into student(name,major,score) values(?,?,?);; pstam=conn.preparestatement(sql); pstam.setstring(1, f); pstam.setstring(2,history); pstam.setint(3, 67); pstam.addbatch(); pstam.setstring(1, h); pstam.setstring(2, biology); pstam.setint(3, 85); pstam.addbatch(); pstam.executebatch(); conn.commit(); }catch(sqlexception e){ try { conn.rollback(); } catch (sqlexception e1) { // todo auto-generated catch block e1.printstacktrace(); } e.printstacktrace(); }finally{ try { conn.setautocommit(true); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } //release the resource of the program try{ pstam.close(); conn.close(); }catch(sqlexception e){ e.printstacktrace(); } }}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product