20 Star 109 Fork 54

万里数据库/GreatSQL-Doc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ExecJDBC.java 2.50 KB
一键复制 编辑 原始数据 按行查看 历史
GreatSQL 提交于 2024-08-29 10:16 +08:00 . 新增benchmarksql 5.0仓库
/*
* ExecJDBC - Command line program to process SQL DDL statements, from
* a text input file, to any JDBC Data Source
*
* Copyright (C) 2004-2016, Denis Lussier
* Copyright (C) 2016, Jan Wieck
*
*/
import java.io.*;
import java.sql.*;
import java.util.*;
public class ExecJDBC {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
String rLine = null;
StringBuffer sql = new StringBuffer();
try {
Properties ini = new Properties();
ini.load( new FileInputStream(System.getProperty("prop")));
// Register jdbcDriver
Class.forName(ini.getProperty( "driver" ));
// make connection
conn = DriverManager.getConnection(ini.getProperty("conn"),
ini.getProperty("user"),ini.getProperty("password"));
conn.setAutoCommit(true);
// Create Statement
stmt = conn.createStatement();
// Open inputFile
BufferedReader in = new BufferedReader
(new FileReader(jTPCCUtil.getSysProp("commandFile",null)));
// loop thru input file and concatenate SQL statement fragments
while((rLine = in.readLine()) != null) {
String line = rLine.trim();
if (line.length() != 0) {
if (line.startsWith("--")) {
System.out.println(line); // print comment line
} else {
if (line.endsWith("\\;"))
{
sql.append(line.replaceAll("\\\\;", ";"));
sql.append("\n");
}
else
{
sql.append(line.replaceAll("\\\\;", ";"));
if (line.endsWith(";")) {
String query = sql.toString();
execJDBC(stmt, query.substring(0, query.length() - 1));
sql = new StringBuffer();
} else {
sql.append("\n");
}
}
}
} //end if
} //end while
in.close();
} catch(IOException ie) {
System.out.println(ie.getMessage());
} catch(SQLException se) {
System.out.println(se.getMessage());
} catch(Exception e) {
e.printStackTrace();
//exit Cleanly
} finally {
try {
if (conn !=null)
conn.close();
} catch(SQLException se) {
se.printStackTrace();
} // end finally
} // end try
} // end main
static void execJDBC(Statement stmt, String query) {
System.out.println(query + ";");
try {
stmt.execute(query);
}catch(SQLException se) {
System.out.println(se.getMessage());
} // end try
} // end execJDBCCommand
} // end ExecJDBC Class
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/GreatSQL/GreatSQL-Doc.git
git@gitee.com:GreatSQL/GreatSQL-Doc.git
GreatSQL
GreatSQL-Doc
GreatSQL-Doc
master

搜索帮助