public void execSQL(String fileName) {
File myFile = new File(fileName);
if (!myFile.exists()) {
System.err.println("Can't Find " + fileName);
return;
}
try {
DriverManagerDataSource dataSource=new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:hsql://localhost/algz");
dataSource.setUsername("sa");
dataSource.setPassword("");
JdbcTemplate jt=new JdbcTemplate();
jt.setDataSource(dataSource);
BufferedReader in = new BufferedReader(new FileReader(myFile));
String sql;
while ((sql = in.readLine()) != null) {
jt.execute(sql);
System.out.print(".");
}
in.close();
System.out.println();
} catch (IOException e) {
e.getStackTrace();
}
}
posted on 2011-06-22 10:16
紫蝶∏飛揚↗ 阅读(430)
评论(0) 编辑 收藏 所属分类:
Spring 、
数据库