-1

I have one .sql script and want to execute it from a java program using jdbc driver(oracle.jdbc.driver.OracleDriver").

Please guide me how can i execute iniside java program.


EDIT (copied from OP's comment)

import java.util.ArrayList;
import java.sql.*;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;
import java.lang.*;

public class OracleConnection
  { public static void main(String[] args)
        throws Exception
      {
      Connection conn = DriverManager.getConnection(url, username, password);
      SqlScript.execute("/home/hyperion/Oracle/Middleware/EPMSystem11R1/products/Found‌​ation/server/conf/create_oracle_cms.sql");
      }
  }

I want to execute the script in the last line.


navi27
  • 13
  • 1
  • 8
  • This may help you http://docs.oracle.com/cd/B25329_01/doc/appdev.102/b25108/xedev_jdbc.htm – Wundwin Born Sep 16 '14 at 10:34
  • Compile your program and call it with CallableStatement directly from your database. – neshkeev Sep 16 '14 at 10:34
  • Can you provide an example to call a script something like /ap01/oracle/test.sql in java – navi27 Sep 16 '14 at 10:35
  • import java.util.ArrayList; import java.sql.*; import java.io.IOException; import java.util.Hashtable; import java.util.Properties; import java.lang.*; public class OracleConnection { public static void main(String[] args) throws Exception { Connection conn = DriverManager.getConnection(url, username, password); SqlScript.execute("/home/hyperion/Oracle/Middleware/EPMSystem11R1/products/Foundation/server/conf/create_oracle_cms.sql"); } } I want to execute the script in the last line. Please help me – navi27 Sep 16 '14 at 10:50
  • @navi27 add this code to your post. Don't forget to format it(select the code and press for windows CTRL+K) – neshkeev Sep 16 '14 at 11:09
  • 1
    If the script has multiple statements then you'd have to parse each statement out, which isn't trivial depending on the types of statement involved, and execute each one individually. Something called `create_oracle_cms.sql` is likely to have various types of statements I'd have thought. Why would you want to run a one-off script from Java? – Alex Poole Sep 16 '14 at 11:24
  • i'm very new to java. Can some one provide me sample code to call an sql script and execute it. – navi27 Sep 17 '14 at 05:00

1 Answers1

0

You need to register your driver first:

Class.forName(yourDriverClassName);
AndreDuarte
  • 784
  • 1
  • 5
  • 21