ibatis执行SQL脚本没有得到结果?
Propertiesprops=Resources.getResourceAsProperties("maindbconn.properties");Stringurl=...
Properties props = Resources
.getResourceAsProperties("maindbconn.properties");
String url = props.getProperty("connString");
String driver = props.getProperty("driverName");
String username = props.getProperty("userName");
String password = props.getProperty("password");
System.out.println(url);
Class.forName(driver).newInstance();
Connection conn = (Connection) DriverManager.getConnection(url,
username, password);
ScriptRunner runner = new ScriptRunner(conn, false, false);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runner.runScript(Resources
.getResourceAsReader("1.sql"));
runner.runScript(Resources
.getResourceAsReader("2.sql")); 展开
.getResourceAsProperties("maindbconn.properties");
String url = props.getProperty("connString");
String driver = props.getProperty("driverName");
String username = props.getProperty("userName");
String password = props.getProperty("password");
System.out.println(url);
Class.forName(driver).newInstance();
Connection conn = (Connection) DriverManager.getConnection(url,
username, password);
ScriptRunner runner = new ScriptRunner(conn, false, false);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runner.runScript(Resources
.getResourceAsReader("1.sql"));
runner.runScript(Resources
.getResourceAsReader("2.sql")); 展开
1个回答
展开全部
你确保你路径对的?Rosource 默认在java编译后的class目录下
比如
源代码
-src
|-*.properties
|-*.sql
编译后:
-classes
|-*.properties
|-*.sql
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
这两句不要
因为原构造函数如下:
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) {
this.logWriter = new PrintWriter(System.out);
this.errorLogWriter = new PrintWriter(System.err);
this.delimiter = ";";
this.fullLineDelimiter = false;
this.connection = connection;
this.autoCommit = autoCommit;
this.stopOnError = stopOnError;
}
希望我的回答能帮到你!!!!
比如
源代码
-src
|-*.properties
|-*.sql
编译后:
-classes
|-*.properties
|-*.sql
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
这两句不要
因为原构造函数如下:
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) {
this.logWriter = new PrintWriter(System.out);
this.errorLogWriter = new PrintWriter(System.err);
this.delimiter = ";";
this.fullLineDelimiter = false;
this.connection = connection;
this.autoCommit = autoCommit;
this.stopOnError = stopOnError;
}
希望我的回答能帮到你!!!!
追问
path是对的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询