随笔-9  评论-168  文章-266  trackbacks-0
    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数据库

只有注册用户登录后才能发表评论。


网站导航: