用JAVA如何实现执行SQL脚本文件

用JAVA如何实现执行SQL脚本文件,第1张

import java.sql.*

private Connection conn=null

private PreparedStatement pst=null

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")

conn=DriverManager.getConnection("jdbc:odbc:%%1",%%2,%%3)

pst=conn.prepareStatement(<SQL>)

pst.addBatch()

pst.executeBatch()

//pst.execute()

} catch (SQLException e){

e.printStackTrace()

}

finally{

try {

pst.close()

conn.close()

} catch (SQLException e) {

e.printStackTrace()

}

}

读取文件

import java.io.*

FileReader fr=null

BufferedReader reader=null

try {

fr = new FileReader(%%1)

reader = new BufferedReader(fr)

String line

while ((line = reader.readLine()) != null) {

// line

}

} catch (IOException e) {

e.printStackTrace()

} finally {

try {

reader.close()

fr.close()

} catch (IOException e) {}

}

JAVA有exec方法,加上参数判段散去调用

代码片段:

try{

Runtime ce=Runtime.getRuntime()

ce.exec("掘氏sqlplus sql.pl"燃歼)

}

catch(Exception e){

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12514411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存