ScriptRunner(com.ibatis.common.jdbc.*)用法

ScriptRunner类用于执行SQL语句,例如创建数据库schema,或传入缺省或测试数据库等等。 从下面的例子可以认识到它的易用性:

    例子1:使用现成的数据库连接

   Connection conn=getConnection();//some method to get a Connection

  ScriptRunner runner=new ScriptRunner();

  runner.runScript(conn,Resources.getResourceAsReader("com/some/resource/path/initialize.sql"));

   conn.close();

  例子2:使用新的数据库连接

  ScriptRunner runner=new ScriptRunner("com.some.Driver","jdbc:url://db","login","password");

  runner.runScript(conn,new FileReader("/user/local/db/scripts/initialize-db.sql"));

例子3:使用新创建的数据连接

  Properties props= getProperties();//some properties form somewhere

ScriptRunner runner =new ScriptRunner(props);

runner.runScript(conn,new FileReader("/user/local/db/scripts/initialize-db.sql"));




Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=487835

你可能感兴趣的:(sql,.net,jdbc,ibatis,Blog)