Is it Possible to Run SQL Script from Java prog

Hello
Is there any API by which we can run SQl Script file ,
Just by giving database configration parameters and SQL Script file Path ,it will execute that script automatically

You can excute SQL statemetns throught JDBC, but that doesn't have a facility to read those statements from a file. You'd have to write code to read the file and create and execute statements through JDBC. That should be pretty straightforward though.
It's conceivable that there's a third party library out there that does it, if you know what to look for.
If you're not familiar with JDBC, check out http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

Similar Messages

  • Running sqlplus scripts from Java code?

    hi
    I need to programmatically run sqlplus scripts from Java code on a machine that doesn't have sqlplus installed.
    Is there any Java class library available for doing this?

    The Ant approach could probably work for me, thanks for the tip.
    The setup seems rather complex however, given the simplicity of the task. I would prefer just running a Java based SQL*Plus from in a separate process or doing this via an API that would allow me to run SQL*Plus scripts (parse script, substitute variables, run statements).
    Oracle SQL Developer v1.1 appears to include an API that does exactly this.
    The ScriptParser, Substitution and SQLPLUS classes in the oracle.dbtools.raptor.scriptrunner package (oracle.sqldeveloper.jar) seem to do just what I need based on my tests.
    Can I use these classes for this purpose in my application? Is repackaging allowed?
    Does Oracle have any plans for releasing this sort of functionality separately e.g. as part of the Instant Client?

  • Is it possible to execute SAPGUI scripts from java program?

    Hi everyone..
         I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
         Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
         it will be more helpful, if docs related to that are shared..
         Thanks in advance

    Oh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
    Thanks for this answer . . .
    Sharon

  • Running sql script from pl/sql

    Is there any standard way to run an external sql script from pl/sql
    I really appreciate any assistance.

    If you want, I did start writing a function reading and executing statements out of sql script with utl_file.
    can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';
    the function could be extended for DDL, session setting, etc...
    Regards
    Laurent

  • Running  sql scripts from different directory

    Hi
    I have sql scripts in different directories as follows:
    D:\myapp\sql
    - load.sql
    - init.sql
    D:\myapp\sql\schema
    -users.sql
    -structure.sql
    D:\myapp\sql\populate\
    - data1.sql
    - data2/sql
    load.sql call all the other scripts as below:
    @init.sql
    @schema\users.sql
    @schema\structure.sql
    @populate\data1.sql
    @populate\data2.sql
    All my scripts run correctly when I run load.sql from D:\myapp\sql on comand prompt.
    I need a way to run this script from a different directory say D:\ or C:\
    I am writing a installer which will execute from a different directory.
    Right now I get a file not found error for scripts within schema an populate folder.
    Please let me know how can I make this work from a different directory.
    Thanks
    kelvin

    Hi peter. i think you cannot run files spread across different locations.
    --the method which u specified always looks to the defined path                                                                                                                                                                                                                                                                                       

  • Need command to run sql script from sql prompt

    Hi,
    I am beginner in sql i need a command to run sql file from sql prompt.In notepad i have write 10 to 15 tables creation and saved as .sql i want to run this file from sql promp pls some one help.I am very great full to all users in this forum.

    You can also use the 'start' command.
    You may also want to look in the SQLPlus User Guide and Reference (for your release) at the set command for commands to set the number of lines per page, turn headings on or off, and so on:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/toc.htm
    HTH -- Mark D Powell --

  • How to run SQL files from Java?

    Hi,
    Can someone point me towards a link on how to run sql files in Java? Thanks.
    P.S...if I've been completely blind please go easy on me!

    Sorry forgot the formating code thingy
    public static boolean executeScript(File script, Connection conn){
        boolean success = true;
        success = script.exists();
        if(success){
          DEBUG.print("ES::READING SCRIPT:" + script.getAbsolutePath());
          StringBuffer buffer = new StringBuffer();
          success=readScript(script,buffer);
          if(success){
            try{
              String creationScript = buffer.toString();
              Statement st = conn.createStatement();
              int start = 0;
              int end = 0;
              while (end != -1 && start < creationScript.length()) {
                end = creationScript.indexOf("GO", start);
                if (end != -1) {
                  DEBUG.print(creationScript.substring(start, end));
                  st.executeUpdate(creationScript.substring(start, end));
                  start = end + 2; //2 is the length of "GO"
              st.close();
            }catch(Exception e){
              success=false;
              DEBUG.printStackTrace(e);
        }else{
          DEBUG.print("ES::SCRIPT FILE DOES NOT EXISTS");
          success=false;
        return success;
      public static boolean readScript(File script, StringBuffer buffer){
        boolean success = true;
        DEBUG.print("RS:: reading file :" + script.getAbsolutePath());
        try{
          InputStreamReader isr = new InputStreamReader(new FileInputStream(script),"UTF16");
          int ch;
          while ( (ch = isr.read()) > -1) {
            buffer.append( (char) ch);
          if (isr != null)
            isr.close();
        }catch(Exception e){
          success=false;
          DEBUG.printStackTrace(e);
        return success;
      }

  • Running SQL scripts from CF server

    Hi,
    I'm new to ColdFusion, but not to database or web
    development. I'm wondering if there's anyway I can run a SQL script
    on a database from my CF server. I'm running CF 5 on a 2003 Windows
    server with a couple Oracle 9i DBs on the backend. I want to move
    data from one DB to the other, but can't use a DB link between the
    two, so a colleague suggested using CF to migrate the data. Is this
    possible?
    Thanks

    It's possible. For each db, cold fusion needs a connection
    and sufficient permissions.

  • Running SQL scripts from a unix directory

    DB version: 11.2
    os Version : Solaris 5.10
    We have a set of scripts used by DBAs for displaying Tablespace free space info, file size info...etc
    Currently these .sql files (say free_Space.sql) are stored in directory /u02/dba_scripts/ . To execute these scripts a dba has to navigate to this directory and then login to sql* plus and from there execute it like
    SQL > @free_Space.sqlI've recently come across an environment where you can login to SQL*Plus from any directory and you can execute scripts like above from any directory . How is this possible? What settings should i set for this?

    Herbaceous wrote:
    DB version: 11.2
    os Version : Solaris 5.10
    We have a set of scripts used by DBAs for displaying Tablespace free space info, file size info...etc
    Currently these .sql files (say free_Space.sql) are stored in directory /u02/dba_scripts/ . To execute these scripts a dba has to navigate to this directory and then login to sql* plus and from there execute it like
    SQL > @free_Space.sqlI've recently come across an environment where you can login to SQL*Plus from any directory and you can execute scripts like above from any directory . How is this possible? What settings should i set for this?environmental variable SQLPATH

  • Running sql script from unix using

    Hello!
    When i run the following sql, it doesn't executes any statement after the 1st SQL.
    anyone know the reason?
    #!/bin/bash
    set -x
    echo test
    sqlplus /nolog << EOF
    set serveroutput on size 1000000
    conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
    select '1st sql output' from dual;
    exit
    EOF.
    sqlplus /nolog << EOF
    set serveroutput on size 1000000
    conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
    select '2nd sqloutput' from dual;
    exit
    EOF
    --------------------------------

    You have to remove . (dot) after first EOF.
    Best regards
    Maxim

  • Run SQL Script from a a Batch File

    I'm trying to schedulling a SQL Script by Windows Scheduler:
    START 
    "C:\Program Files\Microsoft SQL Server\100\DTS\Binn\dtexec.exe" /FILE "C:\Users\tstjs\TESTESTESTES.sql" /MAXCONCURRENT " -1 " /CHECKPOINTING OFF  /REPORTING EWCDI
    PAUSE
    However, when I run the batch file it giving the error below:
    ...sql" due to error 0xC00CE556 "Invalid at the top level of the document. Line 1, Column 1". This happens when loading a package and the file cannot be opened o r loaded correctly into an XML document. This can be the result of either provid
    ing an incorrect file name to the LoadPackage method or the XML file specified h aving an incorrect format. End Error
    How can I solve that problem?
    Thanks!

    Hi SaQvl,
    As Scott metioned, you shall use sqlcmd to execute a tsql script. You can reference the below link
    Use the sqlcmd Utility
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Execute an SQL Script from Java (myScript.sql) ?

    Hello!
    I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
    I'm connecting to mySQL server using JDBC which works fine, but I was wondering
    how can I run an entire script file, say myScript.sql from within a Java class??
    (an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
    example of an SQL Scritp: myScript.sql>>
    //#create new db
    CREATE DATABASE sample_db;
    //#set active db
    USE sample_db;
    //#set table paramaters
    CREATE TABLE monkeys
    (name CHAR(20),
      age INT UNSIGNED,
      sex ENUM('M','F')
    //#create standard monkeys
    INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
    //#get recordset
    SELECT * FROM monkeys WHERE age < 50;Thanks for your help!

    The way I understand it is that your mysql.sql script file uses ';' as a delimeter between statements. So now what you can do is that read the whole file and put it inside a string/stringbuffer. Now put this string/stringbuffer to a stringTokenizer with delimeter set as ';'. this way you will recieve your exact statements without scratching your heads as where the statements begin/ends. :-)
    Now once you have your statements than its just a matter of executing them against the database.
    hope this helps.

  • Running PHP script from Java apps

    Hi,
    I have a PHP application that opens up a template (MS Word) invoice file, inserts some information in the file (eg. today's date, customer name) and then saves it as a new Word file. My questions are as follows.
    1- How can I call this script from my Java application. Please not that I want to be able to pass parameters (eg. custome name read from a DB) from my Java app. to this script.
    2- Is it possible to print already saved MS Word documents from Java? If so, how?
    3- Is it possible to do what my PHP script is doing in pure Java? I couldn't find a simple way of doing this, that's why I used PHP but I would like to do this in Java if I can.
    thanks in advance,
    Mete

    Don't reply here. Go here instead.
    http://forum.java.sun.com/thread.jsp?forum=54&thread=479160&tstart=0&trange=15
    Cross-listed
    Sorry, I thought this didn't post before.

  • Running a script from java application

    How do I execute a script (sms_setver which requires parameters such ms9qa) from java application using Runtime.exec(). I tried Runtime.getRuntime().exec("sms_setver ms9qa"). But, I get this error:
    Caught: java.io.IOException: CreateProcess: sms_setver ms9qa error=2

    Same way it is actually run from a console command line.
    If you are doing this in windows then it might be using the extension to determine how to run it. If from unix then it might be using the shebang line.
    At any rate figure it out and use that instead. Usually it involves either explicitly using the shell or some other executable and the script is a parameter to that process.

  • Run sql script from database

    Is this possible in some form?
    <cfquery name="name" datasource="dsn">
    #query.sqlstatement#</cfquery>

    Yes, if you mean creating a query as a string, then using
    that in a cfquery. Usually you would need to enclose the query text
    within a PreserveSingleQuotes() function if you have parameters
    that are enclosed within single quotes, something like this
    <cfquery name="name" datasource="dsn">
    #PreserveSingleQuotes(sqlstatement)#
    </cfquery>
    Phil

Maybe you are looking for