Executing a DDL statement from java code

Hi all,
this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
I am trying to create a table in same schema in same db by using 'Copy' command.
Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
        public String cmb_action() {
        // Add event code here...
        try {
            //getting source db connection
            InitialContext initialContext = new InitialContext();
            DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
            Connection sourceconn = ds.getConnection();
            sourceconn.setAutoCommit(false);
            String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
            Statement stat = sourceconn.createStatement();
            stat.executeUpdate(sql);
            sourceconn.commit();
            System.out.println("done");
          catch (Exception ne) {
            // TODO: Add catch code
            ne.printStackTrace();
        return null;
    }

I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
But,
Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
Etc, etc,
Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
Regards
Peter
P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

Similar Messages

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • Executing sqlplus / sqlldr command from java code

    hi,
    I have my application on one server(tomcat) and oracle server is installed on other server. i.e. Both are on different machine.
    Now i want to run sqlplus / sqlldr command on oracle server from my java code.
    Again my script for lodder command is in temp of tomcat.
    How to do that?
    Thanks,

    Hi,
    I am using JDBC to executed queries...but i need to run sqlplus command to run script if some condition is satisfied and same for sqllodder to load large record like 500000. This code is in the thread and is working fine for same machine. Need to execute it on another machine where oracle is installed.
    From command prompt i am able to run sqlplus on Oracle server. Same command I am not able to run from the code. I have shared bin direcotry of Oracle from server.
    Let me know if any query
    Regards,
    Edited by: Sun_Nut on Dec 16, 2007 9:53 PM

  • Executing a .bat file from java code

    Im writing a utility and i need to be able to create and execute a .bat file from my program. I can create the .bat file fine but when i try to execute it nothing happens. I tried to use the following line of code to try to execute the .bat file (called make.bat) :
    try
    String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" C:\\ITS_Test\\make.bat";
    Runtime.getRuntime().exec(parameterString);
    catch (Exception e)
    System.out.println(e);
    The Runtime.getRuntime()exec() method worked fine when trying to execute an excel file but for some reason it dosen't want to work for the DOS prompt. Any ideas?

    Thanks everyone for all the replies.
    I have tried all the above with no luck. Im using netbeans, does anyone think that it could be a problem with the IDE.
    I tired the following code :
    String parameterString = "cmd.exe /C \"C:\\ITS_Test\\make.bat\"";
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    This code does not throw any exceptions but just hangs. I also tried:
    String [] parameterString = {"cmd", "/c", "C:\\ITS_Test\\make.bat"};
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    and:
    String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" \"C:\\ITS_Test\\make.bat\"";
    Process pr = Runtime.getRuntime().exec(parameterString);
    pr.waitFor();
    with the same result. Does anyone know why it just hangs and nothing happens (no exceptions thrown)?

  • Executing db2 import statement from java

    we have developed an web application using J2EE technology on websphere and DB2 as a backend.
    I have to now develop a utility for data uploading from Excel to DB2. we can do it using IMPORT statement now i want to know is it possible to execute IMPORT statement from JSP/ Servelet and using javabeans.

    Yes, it is possible :-)

  • Executing system commands like cd on Linux from Java Code

    Hi,
    I need to execute a few system commands (like cd, ls, tar, etc.,) on RedHat Linux 7.1 from Java code. Any ideas plz.
    best wishes,
    Issac

    Since this thread mentioned using the DOS START command
    from an exec(), I was wondering whether anyone else is
    seeing the odd behavior I am.
    Most of the examples showing how to read stdout and stderr
    while the process is running show simple loops that use
    getInputStream and getErrorStream and do read's until they
    get back -1. Most of these examples are insensitive to the
    state of the Process.waitFor that happens elsewhere and sort
    of rely on the -1 and the waitFor happening roughly together.
    Whenever I use this technique to launch an arbitrary DOS
    command (e.g. Runtime.exec("dir")), it works fine, and
    everything seems to terminate as expected.
    However, when my command is something like:
    Runtime.exec("cmd /c start my.bat")
    where I deliberately use the START command to fork off
    a different process, something odd happens.
    Those simple read loops get an initial burst of stdout/stderr
    bytes from the "start" part of the command. But then eventually,
    these loops do a "read" which blocks on those InputStreams. Now,
    even if my Process.waitFor returns (because the start returned
    immediately), those read loops stay blocked **until that script
    started by 'start' runs to completion**. It is like the child
    of the child is holding those streams open somehow.
    I found that by doing something like an InputStream.available() or
    a BufferedReader.ready( ) check before dropping into the read,
    and allowing the Process.waitFor completion to exit those read loops,
    them I get what I expect -- namely immediate return from the START,
    but apparently complete copies of stdout and stderr.
    Curiously, in the case where the reads block until the child process
    started by START terminates, they still don't get the child's/child's
    stdout and stderr. It is just a long duration thread block that
    yields no data.
    Can anyone explain what is happening to a
    Process.getInputStream( ).read()
    when the process immediately does a START and returns? Why would
    the read( ) stay blocked when the START finished launching a new child
    process?
    ... ron cain

  • Executing jar from java code, then kill parent java code

    Please suggest if there is any best way around on executing jar from java code then killing parent java code.
    a) I have desktop based java application say "Monitor.java" which runs every 5 minutes.
    b) How can I START external java application say "execute.jar" from Monitor.java THEN EXIT Monitor.java
    I tried various options using "ProcessBuilder" and calling bat file but I need Monitor (parent application to EXIT, immediately after calling child (execute.jar)
    Try1) ProcessBuilder builder = new ProcessBuilder("java -jar execute.jar");          
    Process process = builder.start();
    Try2) Runtime r = Runtime.getRuntime();
    Process p = null;
    p = r.exec(new String[] { "cmd", "/c", "start C:/temp/Test.bat" });

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • Execute DDL statements from pl / sql

    Hi !!!!
    I have to create every object (tables, sequences, etc) using a pl / sql block, so I need first looking for the object in the data dictionary and if it doesn't exist execute a ddl statement to create it.
    I wanted to execute at the same "execute immediate " :
    - create table.
    - create synonym for the table created before.
    - comments on table
    - comments on table's columns
    - grants on the table.
    But I found some errors:
    - I can`t have semicolon after every statement so I get an "ORA-00911: invalid character". I did'nt try to scape the semicolon so I need it.
    - I split the execute immediate so now I have one execute immediate for every statement but I got an error in this statement:
    EXECUTE IMMEDIATE 'COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS "COMMENT ON TABLE"  '; The error I get is this:
    ORA-01780: string literal required
    Any suggestions about this ?
    Thanks.

    The comment itself needs to be a SQL string so it needs to be delimited with single quotes not double quotes. You can either use two single quotes
    EXECUTE IMMEDIATE 'COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS ''COMMENT ON TABLE''  ';or you can use the q quoting syntax
    EXECUTE IMMEDIATE q'[COMMENT ON TABLE SYSADM.CVP_PAQ_SMS_REC_PRUEBA IS 'COMMENT ON TABLE'  ]';You cannot combine multiple DDL statements into a single block (well, you could use dynamic PL/SQL, but then your string would have a bunch of embedded EXECUTE IMMEDIATE statements which would presumably not buy you much).
    Justin

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • Help:create tree node dynamically from java code...

    hi there...can anyone give me solution how to create or add tree node dynamically from java code???
    currently i am using tree node to handle my menu...i try to create tree and add treenode dynamically from .java page, but it failed...can anyone give solution how to create tree ui from java code, so i can create a dynamic menu...thanz before...

    Hi:
    Just put the statements you would normally put on a sqlplus command line in jdbc statements and execute them?
    http://www-db.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html#0.1_executeUpdate
    MJG

  • Starting exetutable java file from java code

    Hi I was wondering how I can start a executable java file from java code?
    thanks

    Hi Mkaveli,
    Yes, it's possible. If you have a JAR executable, you've just to call the main method of its starter class. For a simple executable class, just call its main method.
    This way :
    SomeStarter.main(null); // if there's no argumentSmall precision : the executable JAR or class must be specified in the classpath of your application.

  • Problem when connecting locally to Oracle Database 10g from Java code

    Good afternoon,
    I try to connect to my local Oracle 10g from JAVA code. Could somebody tells me what are the 'values' to enter in place of 'value1, value2, value3' in the following:
    final String connectionURLThin = "jdbc:oracle:thin:@value1:value2:value3";
    I tried to put my 'user' and 'pw' credentials I used when connecting with SQL*PLUS:
    value1=my_user_name
    value2=my_pw
    value3=my_schema
    but it doest work. Besides where could have I to put the 'WORKSPACE" name?
    Thanks for any help.
    Claude
    Details:
    ERR MESSAGE----------------------
    Exception in thread "main" java.lang.NoClassDefFoundError: oracle/dms/instrument/ExecutionContextForJDBC
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:365)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:854)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:200)
    at javaapplication6.ConnectionExample.driverManager(ConnectionExample.java:138)
    at javaapplication6.Main.main(Main.java:36)
    Caused by: java.lang.ClassNotFoundException: oracle.dms.instrument.ExecutionContextForJDBC
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
    ... 8 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    ---------------------ERR MESSAGE
    JAVA code------------------it compiles but throw an error when running there -> (*)...
    final String driverClass = "oracle.jdbc.driver.OracleDriver";
    final String connectionURLThin = "jdbc:oracle:thin:@jeffreyh3:1521:CUSTDB";
    final String userID = "scott";
    final String userPassword = "tiger";
    final String queryString = "SELECT" +
    " user " +
    " , TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS') " +
    "FROM dual";
    public void driverManager() {
    Connection con = null;
    Statement stmt = null;
    ResultSet rset = null;
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    con = DriverManager.getConnection(connectionURLThin, userID, userPassword); // (*) prob here
    stmt = con.createStatement ();
    rset = stmt.executeQuery(queryString);
    rset.close();
    stmt.close();
    } catch (SQLException e) {e.printStackTrace();
    --------------------JAVA JDK 1.6
    My system ------------------------
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production

    Yes, the network connection could not be established. Like the error said.
    What you're asking about is the exact reason, but that could be any number of things and not at all related to code. You could have the wrong host, the wrong port. A firewall could be blocking the outgoing connection, a firewall could be blocking the incoming connection. Etc. etc.

  • How to know which user has executed which ddl statement

    Hi All,
    Last week i faced some problem, like some one has truncated the table , so luckily i have the schema backup so i restored it till the last backup taken.
    but i want to know who has executed this ddl statement.
    i know there are some utilities are avaible with oracle, so please describe me the easiest and quickest way to get this.
    Regards
    Asif

    In order of descending simplicity
    - Use the principle of least privilege to restrict the privileges users have in the database to ensure that they cannot do things like truncating a table
    - Enable auditing of potentially problematic statements. This has to be done before the damage is done, though
    - Create a DDL trigger that logs when users issue DDL. This also must be done before the damage is done.
    - Use LogMiner to go through the archived log files that were generated at the time the table was truncated. This assumes that the database is in ARCHIVELOG mode and that you have the archived logs from last week. Using LogMiner to track down the culprit is also likely to be relatively time-intensive
    Justin

  • Can u access Oracle9i Reports objects from Java Code?

    Hi,
    How can you access Oracle9i Reports (Rel 2) objects like Body, DataSource, Groups etc from Java Code?
    What are the available APIs?
    I went thru the APIs at http://otn.oracle.com/products/reports/htdocs/getstart/docs/Javadocs/oracle/reports/plugin/definition/package-summary.html
    However various constructors stated in these APIs are using classes from "oracle.reports.definition" package which are difficult for me to locate.
    For eg. Report constructor is using oracle.reports.definition.RWReport and there is no API documentation available for RWReport class.
    Please suggest me the site for the above APIs or the method to get a reference to "Report" instance.
    Thanks
    Rakesh.

    Thanks Tugdual for your quick reply.
    Thats exactly what I am trying to do. I want to develop a utility which can have a subset of Report Developer's functionality.
    Currently using Reports Developer & Report Wizard, I can create a report by providing SQL statement and few parameters (like Report Style, Calculated Fields, Template file etc). I want to put all these parameters in a XML file and run my java utility (based on the APIs which I am looking for) which will use these XML parameter file and generate a '.rdf' file.
    Also, could you please suggest me the site for oracle.reports.definition package API or the way to get a reference to oracle.reports.plugin.definition.Report instance.
    Thanks,
    Rakesh

Maybe you are looking for

  • How can I get a refund from an App that I bought?

    How can I get a refund from an app that I bought? I bought an app called Package for MS Office on the 8th of January and I also reported a problem and they have not got back to me with a response. It has been 3 weeks now and I am still waiting for a

  • Stock Transport Scheduling Agreement - error message: 'Stock in transit...

    Stock Transport Scheduling Agreement - error message: 'Stock in transit exceeded' Hi, I do have a question about transport scheduling agreements. I have created a stock transport scheduling agreement via ME37, doc. type LU for a stock material from i

  • 1.) How do you find the dictionary in Apple Mail Program?  2.) How do you add another dictionary?

    1.) How do you find the dictionary in Apple Mail Program?  2.) How do you add another dictionary?

  • DNG+JPEG?

    My camera, a Panasonic L1, always shoots RAW+JPEG when in RAW mode (no way to turn off JPEG). It turns out there is EXIF info in the JPEG not in the RAW, such as lens info, so I need both in Aperture for full metadata. I'd like to be able to convert

  • IFS ALERT NOTICE FOR JDBC MEMORY LEAK FIX

    IFS ALERT NOTICE FOR JDBC MEMORY LEAK FIX Product and Version Affected: Product: Oracle Internet File System Product ID: 7 Version: 1.0 Description: There is a memory leak when retrieving or saving BLOBs through JDBC. IFS will appear to continue to i