Oracle cast()+PreparedStatement

Hi,
I have a SQL query: SELECT * FROM mytable WHERE mydate = :mydate
mydate is a TIMESTAMP, but i need to cast it to DATE using Oracle function cast(): SELECT * FROM mytable WHERE mydate = cast(:mydate as DATE)
Unfortunatelly i'm using PreparedStatements, so i set the parameter via method setTimestamp()
Is it possible to do the cast anyway?
Thanks

ps = c.prepareStatement("SELECT * FROM mytable WHERE mydate = cast( ? as DATE)");
ps.setTimestamp(1, myTimestamp);
rs = ps.executeQuery();

Similar Messages

  • Failed to Load Oracle.jdbc.PreparedStatement

    Hi all,
    My application says
    "Failed to Load either oracle.jdbc.PreparedStatement or oracle.jdbc.driver.PreparedStatement .
    I have oracle driver in <server-instance>/lib directory.
    Anybody has an idea about this ?
    Thanks

    Hi,
    Here is the server.log meassage at fine Level
    11/Mar/2003:09:06:17] FINE (20766): Status to be set : 0
    [11/Mar/2003:09:06:17] FINE (20766): Invoked receivedReply()
    [11/Mar/2003:09:06:17] FINE (20766): ---SQLPersistenceManagerFactory: dbname = Oracle.[11/Mar/2003:09:06:17] FINE (20766): <-> DBVendorType(), vendorName = [ Oracle] propertyName: oracle short name: ORACLE.
    [11/Mar/2003:09:06:17] FINE (20766): --> DBVendorType.initialize().
    [11/Mar/2003:09:06:17] FINE (20766): --> DBVendorType.load() - resourceName: com/sun/jdo/spi/persistence/support/sqlstore/database/SQL92.properties , override: false.
    [11/Mar/2003:09:06:17] FINE (20766): --> DBVendorType.load() - resourceName: com/sun/jdo/spi/persistence/support/sqlstore/database/ORACLE.properties , override: false.
    [11/Mar/2003:09:06:17] FINE (20766): --> DBVendorType.load() - resourceName: .tpersistence.properties , override: true.
    [11/Mar/2003:09:06:17] FINE (20766): <-> DBVendorType.overrideProperties() - NONE.
    [11/Mar/2003:09:06:17] INFO (20766): Failed to load either oracle.jdbc.OraclePreparedStatement or oracle.jdbc.driver.OraclePreparedStatement. Oracle specific optimization will be disabled.
    [11/Mar/2003:09:06:17] FINE (20766): <-- DBVendorType.initialize().
    [11/Mar/2003:09:06:17] FINE (20766): ---SQLStoreManager: vendor type = ORACLE.
    [11/Mar/2003:09:06:18] FINE (20766): initializeServerLogger: javax.enterprise.resource.jdo.transaction com.sun.jdo.spi.persistence.support.sqlstore.Bundle null
    [11/Mar/2003:09:06:18] FINE (20766): initializeServerLogger: javax.enterprise.resource.jdo.transaction com.sun.jdo.spi.persistence.support.sqlstore.Bundle FINE

  • Help needed, Oracle and PreparedStatement setNull for VARCHAR problem

    Using the JDBC drivers included with JDK 1.3, I am encountering a strange problem when trying use a PreparedStatement with a NULL parameter in a VARCHAR column. When running the code below (user_id is an integer and login is a nullable varchar) the program will simply wait and wait and wait.
    import java.sql.*;
    public class OracleNullTest {
         public static void main(String [] args) {
              try {
              String odbcName = args[0];
              String dbUserName = args[1];
              String dbPassword = args[2];
              int id = Integer.parseInt(args[3]);
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:"+odbcName, dbUserName, dbPassword);
              PreparedStatement ps = con.prepareStatement("Insert into junk(user_id, login) values(?,?)");
              ps.setInt(1,id);
              ps.setNull(2,Types.VARCHAR);
              ps.executeUpdate();
              ps.close();
              con.close();
              } catch (Exception e) { e.printStackTrace(); }
    If I change the 'ps.setNull(...)' to 'ps.setString(2,"test")' things work fine. Furthermore, I've changed the VARCHAR column to a TIMESTAMP and setting it to null works fine. The above code works fine on DB2 and SQL Server so only Oracle is anatagonizing me.
    Any insight or help is greatly appreciated.

    The ODBC driver has nothing to do with java. What you are using in java is a JDBC driver.
    Various microsoft products install a ODBC Oracle driver. Oracle also provides a driver that is installed with the Oracle Client install.
    I have seen reports that suggest the MS driver as good as the Oracle driver, consequently that could be source of your problem.

  • Using an IN predicate in a PreparedStatement

    Is there a clean way to handle the IN predicate in Oracle's PreparedStatement. I guess the obvious way to do it would be thus:
    ps = SELECT * FROM someTable WHERE id IN (?, ?, ?)
    But this means that every time you use a different number of IDs, you would create a new PreparedStatement. If the number of IDs is highly variable, you would end up polluting you statement cache with seldom-used PrepareStatements.
    Is there a easier way to send in a list of values for the IN predicate?

    Fred,
    You can try using an Oracle collection type, like VARRAY that maps to "java.sql.Array" and the TABLE [SQL] operator, but I don't know if this will perform better than a simple "IN" list.
    I think if you search the forum archives for ARRAY, you should find something relevant.
    Good Luck,
    Avi.

  • Scope of PreparedStatement

    If my logic re-creates the PreparedStatement everytime, do I lose the advantage of the PreparedStatement over the Statement class ? Should I instead try to make the scope of my PreparedStatement reference such that it does not get destroyed? Or is the JDBC driver smart enough to recognize a statement that it has already precompiled, and not recompile it again ?

    Speed issues aside, use PreparedStatement whenever you have parameters to the SQL. Don't waste time doing your own date conversions or string ' conversion.
    As to speed: depends on the database. E.g. by my measurements, in Oracle a PreparedStatement is never slower than a Statement, and gets a bit faster when re-used (i.e. one use = same speed, many uses = prepared is faster).
    How often do you execute your most often executed SQL statement? If statement compilation takes a few microseconds, execution a few milliseconds, and you execute a few times a minute -> who cares. You certainly don't want to keep lots of PS's around; they eat up memory at the server, and the microsecond/millisecond/minute math can't make sense for others than the top few SQL statements at best.
    Benchmark your setup: try the program in reply 8 of http://forum.java.sun.com/thread.jsp?thread=504253&forum=48&message=2387589 . Please do tell us what you find out!

  • Error in preparedstatement

    Hi
    Is this preparedstatement valid
    INSERT INTO TABLE2 (COL1,COL2,COL3,COL4)
    SELECT C1,C2,?,? FROM TABLE1 WHERE condn
    When I do con.prepareStatement() on this sql it is giving me error saying
    "Use of parameter marker not valid"
    Is this wrong??

    Is this preparedstatement valid
    INSERT INTO TABLE2 (COL1,COL2,COL3,COL4)
    SELECT C1,C2,?,? FROM TABLE1 WHERE condnOn oracle, that PreparedStatement will compile, but setting the parameters to the column names does not produce the expected result. The Strings are treated as constants, not as column names.
    If you set the parameters like this.
    pstmt.setString(1,"C3");
    pstmt.setString(2,"C4");
    You get the effective SQL being
    INSERT INTO TABLE2 (COL1,COL2,COL3,COL4)
    SELECT C1,C2,'C3','C4' FROM TABLE1 WHERE condn
    Could be different on other DBs.
    -Scott
    http://www.swiftradius.com

  • A better way to do this ?

    where does the sql stuff excute in the following stored procedure, directly in the database or it goes through the oracle VM first ?
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "CustomExport" AS
    import javax.sql.Connection;
    import oracle.jdbc.OracleDriver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class CustomExport
    public void do() throws SQLException{
    OracleDriver oracle = new OracleDriver();
    DriverManager.registerDriver(oracle);
    Connection conn = oracle.defaultConnection();
    PreparedStatement st = conn.prepareStatement("select from table where col=?");
    st.setString(1,"value");
    ResultSet rs = st.execute();
    and is there a better way to read and parse an xml document with PL/SQL.what i've read about is the ability to parse an XML file to load its data directly into a database table.What i was looking for was just a way to parse XML without having to load any data into tables so i did it with java.
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "CustomParser" AS
    import javax.xml.prasers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    public class CustomParser
    private static CustomParseHandler handler = new CustomParseHandler();
    public static void parseXMLFile(String fileName) throws FileNotFoundException,IOException,SAXException
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser parser=saxFactory.newSAXParser();
    parser.parse(new FileInputStream(fileName)),handler);
    private class CustomParseHandler extends DefaultHandler{
    StringBuffer buff;
    public CustomParseHandler()
    this.buff = new StringBuffer();
    public void startElement (String uri, String localName,
    String qName, Attributes attributes)
    throws SAXException
    buff.append("<").append(qName).append(">");
    public void endElement (String uri, String localName, String qName)
    throws SAXException
    buff.append("</").append(qName).append(">").append(newLine);
    public void characters (char ch[], int start, int length)
    throws SAXException
    String fieldName = new String(ch,start,length);
    if(fieldName==null || "".equals(fieldName.trim()))
    return;
    public void clearBuffer(){
    buff.delete(0, buff.length());
    public String getXMLString(){
    return buff.toString();
    }

    PLSQL does not go through Java to access the database. The actual access to the database is via the same mechanism for both, so in some sense, both perform about the same. However, PLSQL datatypes have the same representation as database datatypes so there is no conversion. Java datatypes have different representations than database datatypes so there is a conversion cost associated with moving data between Java and the database.
    If your processing is simple and you are moving a lot of data, PLSQL is likely the better choice. If your processing is more complex and you are moving less data, Java is likely the better choice. There are other things such as portability you should consider, but the amount of data and complexity of the code are the first considerations.
    Douglas

  • Prepared statement and DELETE returns 0 count

    when executing an oracle prepared statement, the count returned is allways 0 for DELETE. However, if doing an INSERT, the count returned is correct
    public void CreatePreparePurgeRcdSetArray(String sql, int i, int max, boolean create) throws SQLException,Exception
    if (create == true)
              if (preparedStatementArray == null)
                   preparedStatementArray = new PreparedStatement[max];
              int scroll_type = getScrollType();
                   if (sql.compareTo("NOT_USED") == 0)
                        preparedStatementArray[i] = null;
                   else
                        preparedStatement          = (connClass.getConn()).prepareStatement(sql);
                        preparedStatementArray[i] = preparedStatement;
                        preparedStatement          = null;
    else
         closePrepareStatementArray(max);
    public int UpdatePreparePurgeRcdSet(Vector smry, String sqlP, int i) throws SQLException,Exception
         Object[] searchs = (Object[])smry.elementAt(0);
         /*java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
         String aaa = searchs[1].toString();
         String aab = searchs[1].toString();
         java.util.Date                     dtx = sdf.parse(aaa);
         java.util.Date                     dty = sdf.parse(aab);
         oracle.sql.DATE aa1 = new DATE(new Timestamp(dtx.getTime()));
         oracle.sql.DATE aa2 = new DATE(new Timestamp(dty.getTime()));
         java.sql.Timestamp      ts1 = (java.sql.Timestamp) searchs[1] ;
         java.sql.Timestamp      ts2 = (java.sql.Timestamp) searchs[5] ;
         boolean oracle = true;
         boolean debug = true;
              if ((oracle == true) && (debug == true))
                   String sql1 = "INSERT INTO FFI_MASTER_PURGE_TBL values ('lmill', 'OSTDEVT', 'sdsadmin', ?, 30, 60, '0', 2, 'ZZZ', ' ')";
                   String sql2 = "DELETE FROM TDSADMIN.FFI_MASTER_PURGE_TBL where FORMATCATEGORY = ?";
                   String sql3 = "DELETE from TDSADMIN.SUMMARY_TBL where (ML_STI_SRC_SYS_CD = ?) AND (ML_STI_CYCLE_CD = ?) AND (ML_STI_FILE_ID = ?)";
                   preparedStatement = (connClass.getConn()).prepareStatement(sql3);
                   //preparedStatement.setString(1, "test");
                   preparedStatement.setString(1, "618");
                   preparedStatement.setString(2, "0114200601");
                   preparedStatement.setString(3, "00001591");
                   oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                   recsDeleted = oraclePreparedStatement.executeUpdate();
              if (oracle == true)
              preparedStatement = preparedStatementArray;
              //oraclePreparedStatement.setExecuteBatch (3);
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              //preparedStatement.setTimestamp(2, ts1);
              //preparedStatement.setObject(2, aa1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(2, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(3, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              //preparedStatement.setTimestamp(5, ts2);
              //preparedStatement.setObject(5, aa2);
         else
                   preparedStatement = preparedStatementArray[i];
              // ML_STI_SRC_SYS_CD
              preparedStatement.setString(1, searchs[0].toString());
                   // ML_STI_SRCSYS_DTTM
              preparedStatement.setTimestamp(2, ts1);
              // ML_STI_CYCLE_CD
              preparedStatement.setString(3, searchs[2].toString());
                   // ML_STI_FILE_ID
              preparedStatement.setString(4, searchs[3].toString());
                   // ML_STI_LOAD_DTTM
              preparedStatement.setTimestamp(5, ts2);
         DateClass dateClass = new DateClass();
              String startTime = dateClass.calToFormattedDateExact();
              try
                   if (oracle == true)
                        //int batch_val = oraclePreparedStatement.getExecuteBatch();
                        oraclePreparedStatement = (OraclePreparedStatement)preparedStatement;
                        recsDeleted = oraclePreparedStatement.executeUpdate();
                        //recsDeleted = oraclePreparedStatement.sendBatch();
                   else
                        recsDeleted = preparedStatement.executeUpdate();
    catch(SQLException e)
         String err = (e.getMessage()).substring(0,e.getMessage().length()-1);
         systemClass.logSqlStatement(sqlP + " : " + err, startTime);
    throw e;
    Message was edited by:
    user539085
    Message was edited by:
    user539085
    Message was edited by:
    user539085

    user539085,
    I guess it returns 0 (zero) because it doesn't delete anything. Can you verify that it did delete some records and still returned zero?
    Good Luck,
    Avi.

  • Which Language is known by only one programmer? and their names. If possible all details

    This is my table structure
    PNAME DOB DOJ GENDER PROF1 PROF2 SALARY
    ANAND 12-APR-66 21-APR-92 M PASCAL BASIC 3200
    ALTAF 02-JUL-64 13-NOV-90 M CLIPPER COBOL 2800
    JULIANA 31-JAN-60 21-APR-90 F COBOL DBASE 3000
    KAMALA 30-OCT-68 02-JAN-92 F C DBASE 2900
    MARY 24-JUN-70 01-FEB-91 F CPP ORACLE 4500
    NELSON 11-SEP-65 11-OCT-89 M COBOL DBASE 2500
    PATTRICK10-NOV-65 21-APR-90 M PASCAL CLIPPER 2800
    QADIR 31-AUG-65 21-APR-91 M ASSEMBLY C 3000
    RAMESH 03-MAY-67 28-FEB-91 M PASCAL DBASE 3200
    REBECCA 01-JAN-67 01-DEC-90 F BASIC COBOL 2500
    REMITHA 19-APR-70 20-APR-93 F C ASSEMBLY 3600
    REVATHI 02-DEC-69 02-JAN-92 F PASCAL BASIC 3700
    VIJAYA 14-DEC-65 02-MAY-92 F FOXPRO C 3500
    and title of this question is my question. How can i get the info. Please tell me with simple logic and efficient query.
    I am enjoying sql queries...

    IF OBJECT_ID('dbo.[test]','U') IS NOT NULL
    DROP TABLE [dbo].[test]
    CREATE TABLE [dbo].[test](
    [PNAME] [varchar](10) NULL,
    [DOB] [date] NULL,
    [DOJ] [date] NULL,
    [GENDER] [char](1) NULL,
    [PROF1] [varchar](30) NULL,
    [PROF2] [varchar](30) NULL,
    [SALARY] [decimal](8, 2) NULL
    INSERT [dbo].[test] ([PNAME], [DOB], [DOJ], [GENDER], [PROF1], [PROF2], [SALARY]) VALUES
    (N'ANAND', '1966-04-12', '1992-04-21', N'M', N'PASCAL', N'BASIC', CAST(3200.00 AS Decimal(8, 2)))
    , (N'ALTAF', '1964-07-02', '1990-11-13', N'M', N'CLIPPER', N'COBOL', CAST(2800.00 AS Decimal(8, 2)))
    , (N'JULIANA', '1960-01-31', '1990-04-21', N'F', N'COBOL', N'DBASE', CAST(3000.00 AS Decimal(8, 2)))
    , (N'KAMALA', '1968-10-30', '1992-01-02', N'F', N'C', N'DBASE', CAST(2900.00 AS Decimal(8, 2)))
    , (N'MARY', '1970-06-24', '1991-02-01', N'F', N'CPP', N'ORACLE', CAST(4500.00 AS Decimal(8, 2)))
    , (N'NELSON', '1965-09-11', '1989-10-11', N'M', N'COBOL', N'DBASE', CAST(2500.00 AS Decimal(8, 2)))
    , (N'PATTRICK', '1965-11-10', '1990-04-21', N'M', N'PASCAL', N'CLIPPER', CAST(2800.00 AS Decimal(8, 2)))
    , (N'QADIR', '1965-08-31', '1991-04-21', N'M', N'ASSEMBLY', N'C', CAST(3000.00 AS Decimal(8, 2)))
    , (N'RAMESH', '1967-05-03', '1991-02-28', N'M', N'PASCAL', N'DBASE', CAST(3200.00 AS Decimal(8, 2)))
    , (N'REBECCA', '1967-01-01', '1990-12-01', N'F', N'BASIC', N'COBOL', CAST(2500.00 AS Decimal(8, 2)))
    , (N'REMITHA', '1970-04-19', '1993-04-20', N'F', N'C', N'ASSEMBLY', CAST(3600.00 AS Decimal(8, 2)))
    , (N'REVATHI', '1969-12-02', '1992-01-02', N'F', N'PASCAL', N'BASIC', CAST(3700.00 AS Decimal(8, 2)))
    , (N'VIJAYA', '1965-12-14', '1992-05-02', N'F', N'FOXPRO', N'C', CAST(3500.00 AS Decimal(8, 2)))
    ;with mycte as (
    select PNAME,DOB, DOJ,GENDER,SALARY, count(PNAME) Over(partition by PROFs) cnt
    FROM test t
    CROSS APPLY (VALUES(PROF1),(PROF2))p(PROFs) )
    Select PNAME,DOB, DOJ,GENDER,SALARY FROM mycte
    WHERE cnt=1

  • BO 5.1.8 - Decimal "zeroed" in reports though DB data contain decimal valu

    Hello,
    I've a problem with a report.
    In my DB2 8.2 db I've a field defined as "DECIMAL" (that contains values with decimal of course...ex.: 100,48).
    In my report, I get all the decimal of that field (and others) rounded like "xxx,00" (ex.: 100,00)
    The values before de decimal are correct, but the values after the decimal are all ",00"
    Within the data manager, I can see the values without decmals (ex: 100), so I weel understand it comes from that part, but how can I change this?
    I've checked the Regional settings of my PC, all possible config in BO and in DB2 client but cannot find a clue for this.
    Any suggestion would be warmly welcomed!!
    Thanks a lot.

    Hi Jean,
    Could you please test the following solutions.
    Solution1:
    1.Change the object definition in the designer by adding Zero (0) or by multiplying with One (1).
    Ex: SalesRevenue*1
    Or
    SalesRevenue+0
    2. Save the Universe and test the issue.
    Solution2:
    Use database-level syntax to convert the numeric database field to a string so that Deski Reports will interpret it as a string type, and display all of the characters.
    For example, in Oracle, cast the number using to_char () and in Microsoft SQL Server use CAST() or STR() prior to adding the field to the report.
    Regards,
    Sarbhjeet Kaur

  • 2 Jdev 11g question

    Hi all,
    I am a Java newbie, so please bear with me.
    Question 1 - How do I make a connection as SYSDBA? The Java program will be running on the database server and the Oracle environment (ORACLE_HOME, ORACLE_SID, etc. will be set).
    Question 2 - This may be moot, depending on the answer to #1 - How do I set the correct class path in order to correctly import oracle.jdbc.PreparedStatement and oracle.jdbc.pool.OracleDataSource?
    I am developing against Oracle database 11.1, but the target databases will be both 10.2.0.3 and 9.2.0.4.
    Thanks for your help.
    Ron Reidy

    #1 try "sys as sysdba"
    #2 double click on the project to get the project properties, go down to libraries and classpath, click on the add library button and find oracle jdbc library.
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                   

  • Number field on crystal report displays Exponential form.

    Number Type field on crystal report printed in Exponential form when digits in this field are more than 17.

    Hi Jay,
    The same issue is addressed in the K-Base article c2005336. This is the limitation in Crystal, If you have more than 15 digits of numberic field it will convert into Exponential
    Use database-level syntax to convert the numeric database field to a string so that Crystal Reports will interpret it as a string type, and display all of the characters.
    For example, in Oracle, cast the number using to_char() and in Microsoft SQL Server use CAST() or STR() prior to adding the field to the report.
    As a workaround to display all the number, I would suggest you to convert it to text using a SQL Expression Field. A SQL Expression field will be evaluated on the database server.
    I would suggest you to follow the below mentioned steps to create SQL Expression field and convert a database field to a string:
    1. Open the report.
    2. Right click the SQL Expression field which is present in the Field Explorer.
    3. Select New and copy and past the below-mentioned text.
    CAST ("Database Field" as varchar)
    Note u201CDatabase Fieldu201D Here you have to mention your database field.
    After you create the SQL Expression Field, insert it on the report and it will display the full number.
    Please note that no calculation can be made on that field since it is now a string.
    I hope this helps you.
    Regards,
    Prashant

  • ORA-01000 during inserting xml files

    Hello,
    I'm using the following jdbc-code to insert xml files into oracle 10gRelease2:
    PreparedStatement stmt = null;
    Connection conn = getConnection();
    try
    stmt = conn.prepareStatement("insert into security values (?)");
    } catch (Exception e) {
    System.err.println(e);
    BufferedInputStream bufferedInputStream;
    for (int i = 1; i < 500; i++)
    String docName = "../../../data/output/security/security" + i+ ".xml";
    try
    FileInputStream fileInputStream = new FileInputStream(docName);
    bufferedInputStream = new BufferedInputStream(fileInputStream, 5000);
    XMLType doc = null;
    doc = XMLType.createXML(conn, bufferedInputStream);
    stmt.setObject(1, doc);
    stmt.executeUpdate();
    doc.close();
    fileInputStream.close();
    } catch (Exception e) {
    System.out.println(i);
    System.err.println(e);
    conn.commit();
    The code is working fine when I insert less than 340 files. But when I try to insert more than 340 files I'm getting the error:
    java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
    ORA-01000: maximum open cursors exceeded
    Where do I open so many cursors? During creating the XMLType?
    Thx,
    Fabian

    I can reproduce this. Looks like a problem with the XMLType.createXML() method. Will confirm and file a bug if necessary. In the mean time the following works and has the same effect
    package com.oracle.st.xmldb.pm.examples;
    import com.oracle.st.xmldb.pm.common.baseApp.BaseApplication;
    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.Reader;
    import java.io.Writer;
    import java.sql.SQLException;
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OraclePreparedStatement;
    import oracle.jdbc.OracleResultSet;
    import oracle.sql.CLOB;
    import oracle.xdb.XMLType;
    public class BulkInsertXMLType extends BaseApplication
       public static String TABLE_NAME  = "Table";
       public static String SOURCE_FILE = "File";
       public static String ITERATIONS  = "Iterations";
       public void doSomething(String[] Args) throws Exception
          OracleCallableStatement  statement = null;
          String statementText;
          XMLType xml;
          CLOB    clob = CLOB.createTemporary( getConnection(), true, CLOB.DURATION_SESSION);
          // statementText = "insert into " + this.getSetting(this.TABLE_NAME) + " values(:1)";
          statementText = "insert into " + this.getSetting(this.TABLE_NAME) + " values(xmltype(:1))";
          System.out.println("GetXMLType.doSomething : Driver Type = " + this.getDriver() + ". Statement = " + statementText);
          statement = (OracleCallableStatement) getConnection().prepareCall(statementText);
          for (int i=0; i < Integer.parseInt(getSetting(this.ITERATIONS)); i++)
            try {
              InputStream is = new FileInputStream(getSetting(this.SOURCE_FILE));
              // xml = XMLType.createXML(this.getConnection(),is);            
              // statement.setObject(1,xml);
              InputStreamReader reader = new InputStreamReader( is );
              Writer writer = clob.setCharacterStream(0);
              char [] buffer = new char [ clob.getChunkSize() ];
              for( int charsRead = reader.read( buffer );
              charsRead > - 1;
              charsRead = reader.read( buffer ) )
                 writer.write( buffer, 0, charsRead );
              writer.close();
              reader.close();
              statement.setCLOB(1,clob);
              boolean result = statement.execute();
              is.close();
              clob.truncate(0);
            catch (SQLException sqle) {
                System.out.println("SQL Exception caught after " + i + "Iterations");
                System.out.println(sqle);
                throw sqle;
          CLOB.freeTemporary(clob);
          statement.close();
          getConnection().commit();
          getConnection().close();
      public static void main (String[] args)
        try
          BulkInsertXMLType example = new BulkInsertXMLType();
          example.initializeConnection();
          example.doSomething(args);
        catch (Exception e)
          e.printStackTrace();
    }

  • Inserting Information into Existing Custom Data Object Using API?

    Hello,
    I have setup a Custom Object and I have the ID for this object. All we're wanting to insert in this object is First Name, Last Name, Email. I have that information in code-form and I have both the BULK API and REST api at our disposal. We are having issues figuring out the API call we want to execute to insert this information into this Custom Object.
    If someone could point us in the right direction that would be amazing. Thank you!

    I solved the problem.
    when we are selecting the image data from access database select that as getbytes
              while(rs.next())
                   count++;
                   picbarray = rs.getBytes("PICTURE");     
    when inserting to the oracle db
    PreparedStatement st1 = null;
    String sql = "insert into (colmn1,colmn2,colmn3,comn4,colmn5) values(?,?,?,?,?)";
    st1 = con.prepareStatement(sql);     
    st1.setString(1, val1);
         st1.setString(2, val2);
         st1.setString(3, val3);
         st1.setBytes(4, picbarray);     
    st1.setString(5, val5);
         st1.executeUpdate();

  • Oracle Prepared Statement Class Cast exception

    I am using the TxDataSource with Oracle thin driver in WL6.1
    I get a ClassCastException when I cast the PreparedStatement
    to OraclePreparedStatement.
    It is unable to cast from weblogic.jdbc.rmi.SerialPreparedStatement.
    I am not if I can use Oracle extensions with a TxDataSource
    Thanks in Advance
    Rajesh

    Don't cast to OracleResultSet but use the WebLogic API to set/get BLOBS:
    http://edocs.bea.com/wls/docs61/oracle/advanced.html#1158561

Maybe you are looking for

  • Cannot delete mail from Archive Folder

    I am in the porcess of tryign Mail again, and i must admitt it is a bit of a challenge. The following problem for example seems so simple but i cannot get it to work. I have a very large Archive folder that was created i believe from the archive fold

  • ITunes Remote App and iPhone 5 and PC

    I just recently downloaded the Remote app from the App Store and I was trying to pair the Remote app with my PC but my PC doesn't see it at all. They're both connected to the same Wi-Fi network as well. I don't understand what I'm doing wrong. Hope t

  • JTabbedPane: Components before and after the tabs themselves.

    I want to make Google Chrome..! Well, really, I want to have GUI stuff up in the title pane. In particular, I want the tabs of a TabbedPane up there. I've concluded that the easiest way to accomplish this (hopefully in a somewhat LaF-neutral way) is

  • Java Plug-In Trace File names

    According to this URL, http://java.sun.com/javase/6/docs/technotes/guides/deployment/deployment-guide/tracing_logging.html , the plug-in trace file should be named as indicated: The names of the trace and log files are plugin<modified version number>

  • JME 3.0 EA under Mac: Emulator 0 terminated while waiting for it to registe

    Hello! I downloaded JME SDK 3.0 from: http://java.sun.com/javame/downloads/sdk30.jsp. After installing I opened it, created new MIDP Application with Hello MIDlet. When I try to run it, the emulator is starting (I see it in the dock), but after coupl