as shown below, use ant.jar to connect to the oracle database and execute the sql script, but if my sql script takes in parameters (for example, through sqlplus: sqlplus user/password@db @ test.sql A B C ), it seems that script parameters are not supported in ant.jar, so I don"t know what good method there is?
public static void main (String [] args) {
SQLExec sqlExec = new SQLExec ();
/ / set database parameters
sqlExec.setDriver ("oracle.jdbc.driver.OracleDriver");
sqlExec.setUrl ("jdbc:oracle:thin:@10.128.x.x:1521:xxsid");
sqlExec.setUserid ("xxuser");
sqlExec.setPassword ("xxpass");
/ the script to be executed
sqlExec.setSrc (new File ("src/data.sql"));
/ / how to deal with
sqlExec.setOnerror ((SQLExec.OnError) (EnumeratedAttribute.getInstance (
SQLExec.OnError.class, "abort"));
sqlExec.setPrint (true); / / sets whether to output
/ / to the file sql.out. If this property is not set, it will be output to the console
sqlExec.setOutput (new File ("src/sql.out"));
sqlExec.setProject (new Project ()); / / by default, otherwise it will make an error
sqlExec.execute ();
}