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 :-)

Similar Messages

  • 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?

  • 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

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • 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.

  • How to execute Dos Command 'Pause' from Java ?

    How to execute Dos Command 'Pause' from Java ?
    I have read the article in javaworld for Runtime.exec() anomalies.
    Can someone please give an insight on this?

    Thanks Buddy!
    That was very useful. Even though its a simple
    solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Patterns to execute a SQL Statement from a Droplet (select)

    Hi,
    I need to perform a query on a table, Example: select * from ARF_QUERY "the database used is Oracle. I would like to know if the atg has some
    standard method to perform this database connection and execute the SQL statement from a Droplet (select).
    Thank.

    I dont think there is any generic droplet to run a select query directly against a table.
    However, there are various lookup droplets available that run on the repositories.
    Like /atg/targeting/RepositoryLookup droplet. you can run it for specific id or for all.
    You might want to have a look at it in documentation of how exactly to use it.
    Thanks

  • Can I execute MySql's command from java application?

    Can I execute MySql's command from java application? And how?
    For example :
    load data local infile 'D:\\myData.txt'
    into table myTable
    fields terminated by ';'
    lines terminated by '\n';

    1. get the jdbc driver for mysql from the mysql site at: http://dev.mysql.com/downloads/connector/j/5.0.html
    2. follow the installation instructiions... which you'll also find in your mysql manual...
    Happy travels. Keith.

  • Import statement in .java files and .jsp files

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import the class I want to use.That is i have to say
    <%@page import="one"%>
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.
    In this case the pSo I am wondering in JSP why it doesn't take the class I am looking for from the classpath .
    Help.

    You have to understand Java scoping rules. In the 1st scenario with the two Java files I am guessing neither one of them begins with a package statement. This means that they belong to the default package. When you compile the compiler uses the classpath to resolve method calls looking in the default package since there was no import statement specified in two.java. JSP is a little different. Now I just read this here in these forums a couple of days ago. Since the classfiles generated from the JSP files are not in the CLASSPATH they are loaded by a different classloader. This is why you have to import all references to all classes in the default package.

  • Import statement in .java files and .jsp files ..correction

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement in two.java I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import one.class in My.jsp .That is i have to say
    <%@page import="one"%>
    in My.jsp.
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder and MyJsp is compiled sucessfully.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.

    It has to do with packages. Most java classes are in a package, the name of which must conform to its place on the filesystem relative to the classpath. By that I mean that if you have com.mystuff.One.java, it must be in a folder com/mystuff where com is located somewhere in the classpath.
    What you've done is a little different. I'm assuming a couple of things:
    1. you have no package declaration at the top of one.java or two.java
    2. you have the current directory "." in your classpath.
    Java has the concept of the "default package", which covers classes without a declared package, and in your case is the current directory.
    So when you're in c:\sourcefolder and run the compiler, then "."="c:\sourcefolder", and that directory is part of the default package. No import statements are necessary for classes that are in the same package. This is why two.java can call methods in one.java without an import statement.
    When you run your jsp, the "current directory" part of your classpath is not c:\sourcefolder, but some other value (probably the directory you start your jsp engine from) You will have to import all non-java-library classes because the jsp itself becomes a java class, with a package that is determined by the jsp engine.

  • DB2 Stored Procedure from Java-JDBC

    Hi All,
    I am using DB2 stored procedure which have been written in COBOL. I have two types of stored procedures. First types of stored procedure takes IN parameter and returns OUT parameter. These stored procedures are working fine. The second type of stored procedure takes IN parameter and returns a CURSOR. According to Database team (who wrote these stored procedure) claims that they can see data in a cursor when they test these stored procedure directly in the database. However, when I run these stored procedures from Java code it returns NULL ResultSet. Here is the code:
    public SearchResult getAllBenefitHEDType(SearchParameter searchParam) throws DAOException {
    log.debug(" getAllBenefitHEDType method - entering ");
    HashMap searchParametersMap = searchParam.getHashMap();
    SearchResult searchResult = new SearchResult();
    String type = (String) searchParametersMap.get(UDFConstant.LOOKUP_SEARCH_TYPE);
    HashMap resultParametersMap = new HashMap();
    ArrayList resultSetDTO = new ArrayList();
    try {
    conn = this.getConnection();
    conn.setAutoCommit(false);
    System.out.println("getAllBenefitHEDType Step 1");
    CallableStatement cs = conn.prepareCall("{call TEST.APS003(?)}"); // Stored Procedure with one IN parameter.
    cs.setString(1,type);
    boolean retVal = cs.execute(); // this should return true if ResultSet is available.. in my case it is returning false.
    // I tried with getting the Object
    ResultSet rs = (ResultSet) cs.getObject(1); // this should give me a valid result set ... in my case I am getting null
    if (rs!=null) {
    System.out.println("getAllBenefitHEDType Step 4A Result Set Not Null");
    } else {
    System.out.println("getAllBenefitHEDType Step 4A Result Set Is Null");
    // I tried getting the resultset
    ResultSet rs1 = cs.getResultSet(); // this should give me a valid result set ... in my case I am getting null
    if (rs1!=null) {
    System.out.println("getAllBenefitHEDType Step 4D Result Set Not Null");
    } else {
    System.out.println("getAllBenefitHEDType Step 4D Result Set Is Null");
    while (rs.next()) {
    System.out.println("getAllBenefitHEDType Step 5");
    LookupDTO lookupDTO = new LookupDTO();
    // the following code populate the Lookup DTOs from ResultSet.

    A few comments...
    1) Creating tables, particularly tables whose names seem to imply that they are temporary tables, on the fly in a stored procedure is a bad idea. That is not the way to work with Oracle, though it is a common practice in other databases like SQL Server. There is undoubtedly a better way to do this in Oracle if you can explain what you're trying to accomplish from a business standpoint.
    2) If you are going to use dynamic SQL, you almost always want to use bind variables, not literals. One of the quickest ways to kill an Oracle database's performance is to not use bind variables.
    3) As has already been mentioned, assuming FH_INICIO is a DATE column, you need to put an explicit TO_DATE around your strings in order to convert them to dates. Otherwise, Oracle's implicit cast depends on the session's NLS_DATE_FORMAT, which is likely to be different in different client applications and from different client machines.
    Justin

  • Multiple sql statements from java

    I am executing sql statements in MaxDB 7.6.04.12 from java using jdbc.
    I want to execute multiple statements at a time, but it seems that however I separate the statements, I get
    com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3014] (at 433): Invalid end of SQL statement
    I have tried separating the statements with just a semi-colon, with a semi-colon and new line, with newline-//-newline (as works with SQL Studio), but whatever I try I get this error or some other.
    Is it possible to do this? and if so how?
    Thanks
    Chris

    Hi Lars,
    Here are the relevant bits of code.
    However I'm not sure how helpful that will be - I'm using the SpringFramework for my jdbc calls, as it saves a lot of time and effort, and my calls are to Spring methods, which are wrappers round the base jdbc calls.
    I'll post it anyway, just in case you're familiar with Spring. I haven't looked at the Spring code, but my understanding is it pretty much just passes the sql to standard jdbc calls.
    I guess my next step would be to trace through the Spring code as it executes and see if anything becomes apparent. However I'm under some time pressure and was hoping to avoid that.
    My other alternative is to create non-temporary tables, and drop them explicitly when I've finished with them.
        public Set<String> getPriceUpdatedProducts() {
            final Set<String> prods = new TreeSet<String>();
            String sql;
            int updates;
            // need single connection template so subsequent statements can access temp tables:
            JdbcTemplate jtSingle = getSingleConTemplate(jdbcTemplate);
            // inDCs is a list of dist channels for an sql 'in' statement:
            String inDCs = "";
            for (String siteId: siteConfig.getAllSiteIds()) {
                if (!"".equals(inDCs)) inDCs += ",";
                inDCs += "'" + siteConfig.getSiteIdProperty(siteId, "distChanId") + "'";
            // Clear all the changed flags from the last run:
            updates = jtSingle.update("update zchangedartdc set changed = '' ");
            // Get the current data into a temp table:
            sql = "create table temp.pricechanges as " +
                  "select A304.matnr, A304.vtweg, konp.kbetr price " +
                  "  from A304 join konp " +
                  "    on A304.knumh = konp.knumh " +
                  "   and A304.mandt = konp.mandt " +
                  "   and A304.vkorg = '" + salesOrg + "' " +
                  "   and A304.vtweg in (" + inDCs + ")" +
                  "   and A304.kschl = '" + rrpCondType + "' " +
                  "   and A304.mandt = '" + sapClient + "' " +
                  "   and konp.kschl = '" + listCondType + "' " +
                  "   and char(date, internal) >= chr(A304.datab) " +
                  "   and char(date, internal) <= chr(A304.datbi) " +
                  "   and A304.kappl = 'V' ";
            jtSingle.execute(sql);
            // Get the changes into a second temp table:
            sql = "create table temp.changedarts as " +
                  "select temp.pricechanges.* " +
                  "  from temp.pricechanges, zchangedartdc " +
                  " where zchangedartdc.matnr = temp.pricechanges.matnr " +
                  "   and zchangedartdc.vtweg = temp.pricechanges.vtweg " +
                  "   and zchangedartdc.price != temp.pricechanges.price ";
            jtSingle.execute(sql);
            // save the changes, and flag them:
            sql = "update zchangedartdc " +
                  "   set (price, changed) = (select price, 'X'  " +
                  "                             from temp.changedarts " +
                  "                            where zchangedartdc.matnr = temp.changedarts.matnr " +
                  "                              and zchangedartdc.vtweg = temp.changedarts.vtweg) " +
                  " where matnr||vtweg in (select matnr||vtweg from temp.changedarts) ";
            updates = jtSingle.update(sql);
            // add the new items that weren't there last time, and flag them:
            sql = "insert into zchangedartdc " +
                  "select '" + sapClient + "', matnr, vtweg, 'X', price " +
                  "  from temp.pricechanges " +
                  " where matnr||vtweg not in (select matnr||vtweg from zchangedartdc) ";
            updates = jtSingle.update(sql);
            // now we've got all the changes flagged, we can get the list of changed products:
            jtSingle.query("select distinct matnr from zchangedartdc " +
                           " where changed = 'X' ",
                           new RowCallbackHandler() {
                               public void processRow(ResultSet rs) throws SQLException {
                                   prods.add(rs.getString("matnr"));
            // release the connection:
            destroySingleConnection(jtSingle);
            return prods;
         * Return a JdbcTemplate which will always use the same connection. Parameter jt is just
         * a convenient way to get a DataSource from which to get a Connection.
         * When the calling prodedure has finished, it MUST call
         * destroySingleConnection(jt)
         * @param jt
         * @return
        private JdbcTemplate getSingleConTemplate(JdbcTemplate jt) {
            Connection con;
            try {
                con = jt.getDataSource().getConnection();
                con.setAutoCommit(true);
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to get Connection for SingleConnectionDataSource", e);
            SingleConnectionDataSource singleDs = new SingleConnectionDataSource(con, true);
            return new JdbcTemplate(singleDs);
        private void destroySingleConnection(JdbcTemplate singleConJt) {
            try{
                ((SingleConnectionDataSource)singleConJt.getDataSource()).destroy();
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to destroy SingleConnectionDataSource", e);

  • Executing a shell script from java using runtime.exec()

    Hi I am trying to create a script (test_script) and execute it -- all within one java program...
    the code compiles and executes perfectly but nothing happens. This is probably because the script does not get changed to the '777' mode although i am trying to do that ... any suggestions ???
    //code
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
         public ScriptBuilder() {
         public void writeScript() throws java.io.IOException{
         FileWriter writer = new FileWriter(new File("test_script"));
              writer.write("#! /bin/sh\n");
              writer.write("cd prodiags\n");
              writer.write("tar cvf delTask.tar delTask\n");
              writer.write("rm -rf delTask\n");          
              writer.flush();
              writer.close();
    Runtime rt= Runtime.getRuntime();
    String[] cmd = new String[3];
    cmd[0] = "ls";
    cmd[1] = "chmod 777 test_script";
    cmd[2] = "./test_script";
    rt.exec(cmd);
         public static void main (String[] args)throws java.io.IOException
         ScriptBuilder sb = new ScriptBuilder();
         sb.writeScript();
    }

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

Maybe you are looking for

  • PO Confirmation Date (OA) & Inbound Delivery Date  Report

    Dear All, Please let me know SAP Standard Report PO Confirmation Date (OA) & Inbound Delivery Date  Report Regards Amey

  • How can I change apostrophe & quote from curly to straight. I'm using Word.

    I'm using a brand new Mac book Pro with word loaded in it. The curly quote marks and apostrophes mess up my feeds and translate as question marks inside of dark diamonds. I know this can be fixed because my 2007 mac book pro did the same thing regard

  • BAPI/FM ( tran MI09) to enter count without ref. to inventory doc

    hi, I wanted a function module/BAPI that can be used to enter count for physical inventory WITHOUT reference to inventory document(transaction MI09) I found a BAPI to enter count for physical inventory with reference to inventory document(transaction

  • Curve 8310 - Contact Dbase(s)

    Hi, I had some how ended up with three Desktop data bases for my contacts, each with a different number of records in. I followed one of the online set of instructuctions for consolidating these dbases HOWEVER I managed to use the wrong set of instru

  • Oracle DB Connect Date Selection

    Hi All, I have managed to extract from Oracle db connecting through DB connect, I'm currently having the problem of limiting my extraction using the date data selection. I have declared the date to be numc 10, and when the data is extracted over my d