Source sql command in java

Hi, is there any way to run source sql command direct in java, or i have to write a method to do that.

statement, but why java doesn't use such a method
and save our time.IMHO this would be outside (way) the scope of a
general purpose programming language like Java. And,
I would argue, outside the scope of the JDBC
packages.
It might be in the scope of a utility package but
really it is a job for a database utility.Exactly. For instance, the Hypersonic database (hsqldb.jar) comes with a SqlTool class (or something like that) that you can call. That class will read and execute a .sql script. Other database products may come with other similar tools.

Similar Messages

  • Using OLE DB Source (SQL Command) as input to DQS Data Services

    Hi,
    I am using an OLE DB Source(SQL Command) as the input to my DQS Cleansing task.
    When I preview in design view my SQL Command I see rows returned.
    Yet at runtime no rows are sent to the DQS Cleansing Task.
    Can I use an OLE DB Source(SQL Command) as an input to a DQS Cleansing Task?
    Any ideas why it sends no records?
    Thanks,
    C.
    CG

    NuTech, is this still an issue?
    Thanks!
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • Sql+command in java

    how may i give the sql command "@c:\\emp.txt" in java?
    how can i then print the result on a jframe?
    thanks, danny

    No can do.
    Unless you want to exec "sqlplus" as an external process, as in:
      String oracle_home = ....;       // system-dependent
      String login = "user/user@instance";  // should come from user
      String cmdline =
        oracle_home + "/sqlplus " + login + " " + "@c:/temp/scr.txt";
      Process proc = Runtime.getRuntime().exec(cmdline);
      // Read the contents of proc.getInputStream() until you
      // get the EOF.

  • Executing SQL command in Java on Linux OS

    when i am running a java class file from cmd line,
    in that java file i am using a SQL statement, like
    select * from emp where empname='uday'
    here its not accepting the single quote('), its ignoring single quotes
    can any one help me

    when i am running a java class file from cmd line,
    in that java file i am using a SQL statement, like
    select * from emp where empname='uday'
    here its not accepting the single quote('), its
    ignoring single quotes
    can any one help meIf you were using a prepared statement then this would be irrelevant. I suggest you take a look at one before you have to right some larger queries.
    http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    http://www.javaworld.com/javaworld/jw-01-2002/jw-0125-overpower.html

  • Read from sql task and send to data flow task - [OLE DB Source [1]] Error: A rowset based on the SQL command was not returned by the OLE DB provider.

    I have created a execut sql task -
    In that, i have a created a 'empidvar' variable of string type and put sqlstatement = 'select distinct empid from emp'
    Resultset=resultname=0 and variablename=empidvar
    I have added data flow task of ole db type and I put this sql statement under sql command - exec emp_sp @empidvar=?
    I am getting an error.
    [OLE DB Source [1]] Error: A rowset based on the SQL command was not returned by the OLE DB provider.
    [SSIS.Pipeline] Error: component "OLE DB Source" (1) failed the pre-execute phase and returned error code 0xC02092B4.

    shouldnt setting be Result
    Set=Full Resultset as your query returns a resultset? also i think variable to be mapped should be of object type.
    Then for data flow task also you need to put it inside a ForEachLoop based on ADO.NET recordset and map your earlier variable inside it so as to iterate for every value the sql task returns.
    Also if using SP in oledb source make sure you read this
    http://consultingblogs.emc.com/jamiethomson/archive/2006/12/20/SSIS_3A00_-Using-stored-procedures-inside-an-OLE-DB-Source-component.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Pass a variable value to SQL Command in OLEDB Source

    Hi,
      I have the OLEdb Source where it has SQL Command as Data Access Mode. Below is the sample query that i have in that.
    DECLARE @MonthOffSet int = 24
    DECLARE @PaidDate_SK_Low datetime = dateadd(mm,MONTH(getdate())-@MonthOffSet-1,dateadd(year,datediff(year,0,dateadd(YY,0,getdate())),0))
    DECLARE @PaidDate_SK_High datetime = dateadd(dd,-1,dateadd(MM,@MonthOffSet,@PaidDate_SK_Low))
    followed by select statement which has where clause.
     Instead of hard code the value 24, i am trying to get the value from variable. I know there is a limitation to add the parameters only in where clause. Is there any work around or solution.

    But i need to use the first four lines of code in lot other packages which has different sql statement. But if i make whole query variable then i have a limitation on length 4000 char.
    DECLARE @MonthOffSet int = 24
    DECLARE @PaidDate_SK_Low
    datetime = dateadd(mm,MONTH(getdate())-@MonthOffSet-1,dateadd(year,datediff(year,0,dateadd(YY,0,getdate())),0))
    DECLARE @PaidDate_SK_High
    datetime = dateadd(dd,-1,dateadd(MM,@MonthOffSet,@PaidDate_SK_Low))
    in my select statement in where clause i am using date range between @PaidDate_SK_Low
    datetime  and @PaidDate_SK_High
    datetime 
    Any suggestions

  • Connect to MS Sql Server from Java Source

    Hi,
    Is there any way I could connect to ms sql server from Java source? I know I can call java source from function thats easy but what I really want is capability to connect to non-oracle(MS SQL server) from my java source and then call it from function.
    I don't know if JDBC driver for SQL server is even installed/available. Is there a way I could find it out form my IDE? I know sqlJ does compile but I have never used sqlj. help!!!
    Sinha

    You'll probably have better luck in a Java forum or a Microsoft forum.

  • How to use Java with PL/SQL commands to send an email with attachment

    Apologizes in advance if this is the wrong place to ask the question.
    I need to use Java with PL/SQL commands to send an email with attachment. My java application runs from the command line and does some magic to gather info from an Oracle 11g db. If the DB has sendmail configured, I'd like to send the results of the data gathering as an attachment to the email addresses. I'm not sure how to do this. I've been reading up on on PL/SQL can send email with UTL_SMTP - with attachments. I'm just not sure how to translate that into being triggered by my Java application. Any suggestions or pointers on what I should read would be appreciated.
    Background - I've been programming in Java for 10+ years, but this is my first time using databases. I also have been on these forums for a long time, but lost my profile when it was switched to Oracle.
    Thanks for all help.

    user13726880 wrote:
    The original requirements were put together and given to me, an Oracle newbie. They expected the Java app to use something intrinsic to Oracle and Unix sendmail. To solve my problem, I use a JDBC connection to run some SQL commands. I take that data, format it and send the results by email to the user. By default the requirement is to send it as an HTML attachment using Unix 'sendmail'. So I do that using Runtime exec. I have also added JavaMail functionality as an alternative to sendmail. It works great and as expected.Sounds like a reasonable solution.
    Note however that PL/SQL itself can send email. And PL/SQL can call unix sendmail too.
    However myself I would have done it in java with JavaMail.

  • Java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

    Jdeveloper 11.1.1.6
    WLS 10.3.5
    The screen in our application polls at a fixed interval, The screen renders properly and the poll too works good. but intermittently we get the error below. and there will be no data in the screen. and if reload the screen it works good.
    This doesn't happen in dev and is happening in clustered env only.Please suggest.
    java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
    Thanks

    Habe you tested your application with application module polling turned off? 
    Errors like this are most often the result of activation/passivation problems in the application.  Check out http://tompeez.wordpress.com/2011/07/08/jdev-always-test-your-app-with-applicationmodule-pooling-turned-off/ for more info.
    Timo

  • Capture and Save SQL Command that Ran in OLEDB Data Source

    Hi,
    My company is using SSIS to occasionally generate a file that is then being loaded into a transactional system.  At this point, things are not fully automated; the SQL query that is used for the data source is manually altered, SSIS is run, and the
    file is uploaded to the other system.  Every time the SSIS package runs, a log entry is created with summary information.
    I'm wondering: is it possible to capture the SQL command that runs in the data source, and save it with the log entry as part of the package run?  This would provide an accurate historical record of what filters were applied to the data that was loaded
    to the transactional system.
    Any thoughts/comments would be appreciated.

    Hello Smith,
    What I understood from your question that you want to know the query which is running in SSIS Data Source and same you want to insert into a table.
    Below query gives you what all queries are currently running on a specified DB:
    USE [SAMPLE_DB_NAME]
    SELECT  distinct getdate(), command, s.text, start_time, percent_complete, CAST(((DATEDIFF(s, start_time, GetDate())) / 3600) AS int) AS Long, CAST((DATEDIFF(s, start_time, GetDate()) % 3600) / 60 AS int) as LongMin, CAST(((DATEDIFF(s, 
                          start_time, GetDate())) / 3600) AS varchar) + ' hour(s), ' + CAST((DATEDIFF(s, start_time, GetDate()) % 3600) / 60 AS varchar) + 'min, ' + CAST((DATEDIFF(s,
                           start_time, GetDate()) % 60) AS varchar) + ' sec' AS running_time, CAST((estimated_completion_time / 3600000) AS varchar) 
                          + ' hour(s), ' + CAST((estimated_completion_time % 3600000) / 60000 AS varchar) + 'min, ' + CAST((estimated_completion_time % 60000) 
                          / 1000 AS varchar) + ' sec' AS est_time_to_go, dateadd(second, estimated_completion_time / 1000, getdate()) AS est_completion_time, blocking_session_id, r.status, last_wait_type,
    r.open_transaction_count, r.session_id, client_net_address, 
     CONVERT(VARCHAR(20), sp.host_name) as hostname, 
     CASE WHEN program_name = '.Net SqlClient Data Provider                      ' THEN 'Reporting Service'
     ELSE CONVERT(VARCHAR(50), program_name) 
     END as program_name,
     sp.login_name as name
    FROM         sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) s INNER JOIN
                          sys.sysusers u ON r.user_id = u.uid
    INNER JOIN sys.dm_exec_connections dec ON dec.session_id = r.session_id INNER JOIN SYS.dm_exec_sessions sp on r.session_id = sp.session_id
    WHERE text not like 'SELECT     getdate(), command, s.text, start_time, percent_complete%'
    AND text not like '%sys.sp_trace_getdata%'
    AND text != 'sp_server_diagnostics'
    ORDER BY start_time
    You can schedule this query to run in 2-3 second and can capture the T-SQL and insert into a table.
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • Error at Data Flow Task [OLE DB Source [1]]: No column information was returned by the SQL command." error

    I have an .XLSX File that I am trying to Upload into SQL Server.  I use the Source as OLEDB Connection manager and pick OLDEB PROVIDER as MS OFFICE 12.0 ACCESS DATABASE ENGINE. In that I put this query but it gives the foll
    error when I run the SSIS Package.
    [OLE DB Source [1]] Error: No column information was returned by the SQL command.
    Query I use in DATA FLOW TASK  , IS SQL COMMAND:
    Select top 1 [Investor #],[Investor Name], CONVERT (VARCHAR(1000),Delegation)AS DELEGATION ,[Date Added],[Date Revised] from [EXCELSHEET1$]
    Any suggestion to fix this error? i have to do a convert since the excel datayype is DT_TEXT AND SQL TABLE DATATYPE is VARCHAR(1000)  SO Have to do this Convert.

    If the target table's column is not a BLOB/CLOB (e.g. NVARCHAR(MAX)) and you have text longer than the max value it will not fit into the target, if you are allowed you need to trim it and convert, otherwise sure you get the error as the target datatype
    is smaller. 
    Arthur My Blog

  • Running a SQL*Plus command from Java

    I have a requirement to run SQL* Plus commands from Java. The results as they would appear in SQL*Plus window or spool file should be captured and stored in a table.
    For example,
    SQL> select * from dual;
    D
    X
    1 row selected;
    SQL>
    All the lines above should be stored for later use.
    Could any one give pointers?
    Thanks,
    Ravi

    <p>
    Hi,
    </p>
    <p>
    <strong><font face="Courier New">
    public class RuntimeExecApp {
     public static void main(String args[]) throws IOException
      Runtime r = Runtime.getRuntime();
      r.exec(&quot;C:\\Oracle\\sqlplus.exe&quot;);
    }</font></strong>
    </p>
    <p>
    Kuba 
    </p>
    Message was edited by:
    KUBA

  • Csv to sql commands

    hi ,
    I am using the below file to convert my csv file to sql commands. I am currently trying to update the contents of the stationary csv. So i replace the existing stationary csv with the new stationary csv, then run the make-sql.sh which creates an oracle compatable sql script all.sql....now my problem is that this all.sql is not getting updated right. i.e. when i compare the csv file and the all.sql there are fields that hold different data...pls let me know what cld be causing this....
    make-sql.sh
    #!/bin/sh
    GX_ROOTDIR=/apps/iasdev06/ias6/ias
    JAVA_HOME=/apps/iasdev06/ias6/ias/usr/java
    RMI_IIOP_HOME=${GX_ROOTDIR}/orbtools
    PATH=${JAVA_HOME}/bin:$PATH
    CLASSPATH=$GX_ROOTDIR/classes/java/ktjdk11.jar:$GX_ROOTDIR/classes/java/kadmin.jar:$JAVA_HOME/lib/tools.jar
    CLASSPATH=$GX_ROOTDIR/classes/java/ldapjdk.jar:$GX_ROOTDIR/classes/java/SWING.JAR:$GX_ROOTDIR/ias/APPS:$GX_ROOTDIR/APPS:$JAVA_HOME/jre/lib/rt.jar:$CLASSPATH
    CLASSPATH=$GX_ROOTDIR/classes/java/jdbc20.jar:$GX_ROOTDIR/classes/java/javax.jar:$GX_ROOTDIR/classes/java/kfcjdk11.jar:$GX_ROOTDIR/classes/java:$JAVA_HOME/lib/classes.zip:$CLASSPATH
    CLASSPATH=$GX_ROOTDIR/classes/java/servlet.jar:$CLASSPATH
    PKG=com.dupont.refrigerants.distributorlocator
    cd ../..
    SOURCE=`pwd`
    GENERATE_SQL=$JAVA_HOME/bin/java\ -classpath\ ${SOURCE}/build/lib/classes:${CLASSPATH}\ -Djava.compiler=NONE\ ${PKG}.DistributorDBABeanImpl\$GenerateInsertFromCSV
    cat < ${SOURCE}/buildscripts/datasource/prolog.sql > all.sql
    ${GENERATE_SQL} ${SOURCE}/buildscripts/datasource/stationary.csv 1 US | sort | uniq >> all.sql
    ${GENERATE_SQL} ${SOURCE}/buildscripts/datasource/canada.csv 1 CA | sort | uniq >> all.sql
    ${GENERATE_SQL} ${SOURCE}/buildscripts/datasource/mobile.csv 2 US | sort | uniq >> all.sql

    Hi,
    What you are doing here is, generating some data with prolog.sql and then, your main logic to csv to sql is in the Java program GenerateInsertFromCSV.java .
    So, you need to find out the logic of that code. The shell script is not doing anything apart from calling the Java code.
    Have a deep look into the same.
    Regards

  • OLEDB Source sql query with parameter

    I have a dataflow  in a for each loop container.The OLEDB Source is pointing to oracle database.The sql query to fetch the data should take a variable value.
    Example : select * from tablename where colname = @variablevalue
    the variable value changes each time since the dataflow is in a for each loop container.
    can anyone please help me configuring the source??
    when i try to use ? i get the following error message
    Thanks,
    Rahul

    I can't troubleshoot that error as i don't have a Oracle source to test. See this - 
    http://microsoftdw.blogspot.com/2005/11/parameterized-queries-against-oracle.html
    Try -
    1. Create a int variable vBatchIndex (this would be your parameter which you are trying to pass) and provide the value
    2. Create another string variable vSQLQuery > Go to Variable properties > Set the "EvaluateAsExpression" property to "True"
    3. Under the variable properties > Go to Expression > and provide this expression as 
    "SELECT * FROM fc_batch_report WHERE batch_index= " + (DT_WSTR, 10) @[User::vBatchIndex]
    4.Next ,go to OLE DB Source > Select the Data access mode - SQL command from variable
    5.Select the variable name - vSQLQuery 
    Narsimha

  • Accessing MS Sql Server with Java classes - problem connecting to socket

    I found an example at this location which uses java classes to connected to MS Sql Server.
    http://search400.techtarget.com/tip/1,289483,sid3_gci1065992,00.html
    --bummer - it is a login location - so I will include the article
    Anyway, the example is using Websphere, but I am still on Jbuilder (will get wsad soon). So I planted the classes from the example in
    C:\Borland\JBuilder\jkd1.4\jre\lib\ext\...the classes
    Then I copied the code from the example to my jpx project and got an error that it could not connect to the socket. The only thing I changed in the code was the connection string:
    --original string from example:
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://1433", "");
    I was getting an error with the 2 argument version of DriverManager - and the second argument here was empty (properties argument). Here was my connection string:
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://Myserver:1433;User=sa;Password=");
    I am only using the 1 argument version of DriverManager. Note that the password=" is blank because my RnD workstation is standalone - no one accesses the sql server except me - so no password. I also left out the last semicolon I noticed. Any suggestions appreciated how I could fix this.
    Thanks
    source of article:
    http://search400.techtarget.com/tip/1,289483,sid3_gci1065992,00.html
    iSeries 400 Tips:
    TIPS & NEWSLETTERS TOPICS SUBMIT A TIP HALL OF FAME
    Search for: in All Tips All search400 Full TargetSearch with Google
    PROGRAMMER
    Sample code: Accessing MS SQL Server database from the iSeries
    Eitan Rosenberg
    09 Mar 2005
    Rating: --- (out of 5)
    Nowadays with the help of Java the iSeries can be integrated with other databases quite easy. This tip shows you how. The code included here uses the free Microsoft driver that can be downloaded from here. (SQL Server 2000 Driver for JDBC Service Pack 3)
    If your SQL server does not include the Northwind Sample Database you can find it here.
    http://www.microsoft.com/downloads/details.aspx?familyid=07287b11-0502-461a-b138-2aa54bfdc03a&displaylang=en
    The download contains the following files:
    msbase.jar
    mssqlserver.jar
    msutil.jar
    Those files needs to be copied to the iSeries directories (/home/r_eitan/ExternalJARs).
    Here's the directory structure (on the iSeries) for this sample:
    /home/r_eitan/ExternalJARs - Microsoft files (msbase.jar,mssqlserver.jar,msutil.jar)
    /home/r_eitan/JdbcTest02 - My code (Main.java,Main.class)
    The Java code
    import java.sql.*;
    import java.io.*;
    class Main {
    * Connect to Microsoft SQL server and download file northWind.products as tab
    * seperated file. (products.txt)
    public static void main(String args[]) {
    try {
    PrintStream outPut = new PrintStream(new BufferedOutputStream(new FileOutputStream("products.txt")));
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    //Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://1433", "");
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://Myserver:1433;User=sa;Password=");
    System.out.println("Connection Done");
    connection.setCatalog("northWind");
    String sqlCmdString = "select * from products";
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(sqlCmdString);
    ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
    int columnCount = resultSetMetaData.getColumnCount();
    // Iterate throught the rows in resultSet and
    // output the columns for each row.
    while (resultSet.next()) {
    for (int index = 1; index <=columnCount; ++index)
    String value;
    switch(resultSetMetaData.getColumnType(index))
    case 2 :
    case 3 :
    value = resultSet.getString(index);
    break;
    default :
    value = """ + resultSet.getString(index) + """;
    break;
    outPut.print(value + (index < columnCount ? "t" : ""));
    outPut.println();
    outPut.close();
    resultSet.close();
    connection.close();
    System.out.println("Done");
    catch (SQLException exception)
    exception.printStackTrace();
    catch (Exception exception)
    exception.printStackTrace();
    --------------------------------------------------------------------------------------------------

    My guess is that the server's host name isn't right. It necessarily (or even usually) the "windows name" of the computer. Try with the numeric IP address instead (type "ipconfig" to see it).
    First aid check list for "connection refused":
    - Check host name in connect string.
    - Check port number in connect string.
    - Try numeric IP address of server host in connect string, in case name server is hosed.
    - Are there any firewalls between client and server blocking the port.
    - Check that the db server is running.
    - Check that the db server is listening to the port. On the server, try: "telnet localhost the-port-number". Or "netstat -an", there should be a listening entry for the port.
    - Try "telnet serverhost the-port-number" from the client, to see if firewalls are blocking it.
    - If "telnet" fails: try it with the numeric ip address.
    - If "telnet" fails: does it fail immediately or after an obvious timeout? How long is the timeout?
    - Does the server respond to "ping serverhost" or "telnet serverhost" or "ssh serverhost"?

Maybe you are looking for

  • Problem with adobe premiere CS5 file not responding

    I have a problem with Adobe Premiere software, some time ago I was given a file in Adobe Premiere project contains a hard drive to my revision. but when i try to do the project on my computer I was often faced with the problem of not responding. What

  • IMovie 09 BUG ? Amendments to Titles not reflected.

    Something irritating happens to me in using iMovie '09. I made a short 5 mins movie, after testing and what not & after being satisfied, I then goto Share > Export Movie, type a filename then press ENTER. A message then appeared and say "Preparing pr

  • Problem when loading pdf files from Shared Content

    When I load pdf files from Shared Content, I got the following problem: "The selected document could not be retrieved, please try uploading the document again." Anyone knows this? Thank you very much in advanced.

  • Running Demobld.sql on client work station

    Running Demobld.sql on server works OK (logged on as SYSTEM) when I execute: SQL>@F:\Oracle\Oracle8i\demobld.sql but when logged on on a different workstation (i.e. on client machine) and execute the same command I get: SP2-0310: unable to open file

  • Backup ABAP Programs

    Hi Everyone, I need your help. I am working on a tool that can backup the ABAP source codes and tables. I am using the READ REPORT to get the source code and store the result in a text file, my question is, if I want to give this tool to a client , w