Passing BLOBs through JDBC!

We cannot pass a BLOB into a PL*SQL Stored Procedure, although we can do this direct into a table and we can happily read a BLOB returned as part of the result of an SP.
How can we acheive getting a BLOB into the parameter of a PL*SQL stored procedure?
Any help appreciated,
Thanks
Jason.

If anyone can help, here are some details on the problems I have come across:
I have Oracle 8.1.7 installed on a i86 running Redhat linux 6.2. I am using the thin driver with JDBC.
I have the following stored procedures:
Procedure binarySPA( rsReturn out tDynamicCursor,
vBinary in BLOB,
vMimeType in VARCHAR2 );
Procedure binarySPB( rsReturn out tDynamicCursor,
vBinary in VARCHAR2,
vMimeType in VARCHAR2 );
I am able to add any binaries I like using the second stored procedure plus upload to table like so:
Connection connection = getConnection();
connection.setAutoCommit(false);
Statement st = null;
ResultSet resultSet = null;
String guid = null;
st = connection.createStatement();
guid = Utils.getUUID();
st.execute ("INSERT INTO tblBinary VALUES (empty_blob(), '" + guid + "')");
resultSet = st.executeQuery("SELECT BINARY FROM tblBinary WHERE GUID='" + guid + "' FOR UPDATE");
resultSet.next();
BLOB blob = ((OracleResultSet)resultSet).getBLOB(1);
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = b.read(buffer)) != -1)
outstream.write(buffer, 0, length);
b.close();
b = null;
outstream.close();
and passing the guid to spAddDocBinaryFromTable, which copies the binary from tblBinary and deletes it from tblBinary.
Unfortunately, this requires external table access, which I would like to avoid, but also doubles the time it takes to add
a binary to the database. Since some of our clients work with image files upwards of 100mb, adding using this method current takes more
than ten minutes. I would really like to reduce this time.
I tried creating the blob using the following java code:
====================================
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class TestBlob4 {
public static void main(String [] argv) {
final int USE_BYTE_ARRAY = 0, USE_OUTPUT_STREAM = 2, USE_TEMPORARY_LOB = 3;
final int TECHNIQUE = USE_TEMPORARY_LOB;
byte [] testData = "this is some test data".getBytes();
ByteArrayInputStream testDataStream = new ByteArrayInputStream(testData);
Connection connection = null;
CallableStatement st = null;
ResultSet resultSet = null;
try {
oracle.jdbc.pool.OracleConnectionPoolDataSource dataSource = new oracle.jdbc.pool.OracleConnectionPoolDataSource();
dataSource.setDriverType("thin");
dataSource.setServerName("xxx");
dataSource.setDatabaseName("xxx");
dataSource.setPortNumber(xxx);
dataSource.setUser("xxx");
dataSource.setPassword("xxx");
connection = dataSource.getConnection();
connection.setAutoCommit(false);
String stString = "{call XXX.binarySPA(:1,:2,:3)}";
st = connection.prepareCall(stString);
st.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
BLOB blob;
switch (TECHNIQUE) {
case USE_BYTE_ARRAY:
blob = new BLOB((OracleConnection)connection, testData);
st.setBlob(2, blob);
break;
case USE_OUTPUT_STREAM:
blob = new BLOB((OracleConnection)connection);
uploadToBlob(testDataStream, blob);
st.setBlob(2, blob);
break;
case USE_TEMPORARY_LOB:
blob = BLOB.empty_lob();
String getString = "{call DBMS_LOB.CreateTemporary(:1,:2)}";
st = connection.prepareCall(getString);
st.setBlob(1, blob);
st.setBoolean(2, false);
st.execute();
uploadToBlob(testDataStream, blob);
st.setBlob(6, blob);
break;
st.setObject(3, "text/plain");
st.execute();
resultSet = (ResultSet)st.getObject(1);
resultSet.next();
System.out.println(resultSet.getString(1));
connection.commit();
} catch (Exception e) {
e.printStackTrace();
if (connection != null)
try {
connection.rollback();
} catch (SQLException err) {
err.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (st != null) st.close();
if (connection != null) connection.close();
} catch (SQLException e) {
e.printStackTrace();
private static void uploadToBlob(InputStream is, BLOB blob) throws SQLException, IOException {
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = is.read(buffer)) != -1)
outstream.write(buffer, 0, length);
outstream.close();
is.close();
====================================
But I get the following errors:
case USE_OUTPUT_STREAM:
java.lang.NullPointerException
at oracle.sql.Datum.getBytes(Datum.java:147)
at oracle.jdbc.driver.OraclePreparedStatement.setDatum(OraclePreparedStatement.java:1408)
at oracle.jdbc.driver.OraclePreparedStatement.setBLOB(OraclePreparedStatement.java:1431)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2013)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2052)
at oracle.sql.LobPlsqlUtil.plsql_getChunkSize(LobPlsqlUtil.java:1201)
at oracle.sql.LobPlsqlUtil.plsql_getChunkSize(LobPlsqlUtil.java:121)
at oracle.jdbc.dbaccess.DBAccess.getLobChunkSize(DBAccess.java:955)
at oracle.sql.LobDBAccessImpl.getChunkSize(LobDBAccessImpl.java:111)
at oracle.sql.BLOB.getChunkSize(BLOB.java:228)
at oracle.sql.BLOB.getBufferSize(BLOB.java:242)
at oracle.sql.BLOB.getBinaryOutputStream(BLOB.java:202)
at TestBlob4.uploadToBlob(TestBlob4.java:101)
at TestBlob4.main(TestBlob4.java:55)
case USE_BYTE_ARRAY:
java.sql.SQLException: ORA-22281: cannot perform operation with an updated locator
ORA-06512: at "XXX.XXX", line XXX
ORA-06512: at line 1
The PL/SQL code is just an assignment:
lBinary := vBinary;
I get the same error when I try an insert the blob into a table.
case USE_TEMPORARY_LOB:
PLS-00306: wrong number or types of arguments in call to 'CREATETEMPORARY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I can't find any other way to get a blob into the database.
Any help is much appreciated, as my colleagues and I have been having a nightmare trying to figure this stuff out.
Jake.
null

Similar Messages

  • Inserting files in to Oracle 8i database through JDBC - Only 4k data file

    Hi,
    I need to insert a files(images or excel files, doc files etc..) in to oracle 8i database through JDBC program. But i am not able to store more than 4k data files in to files. can any body give me solutions regarding this.
    My code is like this...
    String fileName ="Sample.jpg";
                                  String dataSource = "jdbc/oracle";
                   File file=null;
                   FileInputStream fis = null;
                   Context initCtx=null;
                   DataSource ds = null;
                   Connection con = null;
                   try
                        initCtx = new InitialContext();
                        ds = (DataSource)initCtx.lookup(dataSource);
                        con = ds.getConnection();
                      try
                         file = new File(fileName);
                         fis = new FileInputStream(file);
                        catch(FileNotFoundException fe)
                             out.println("File Not Found");
                                            PreparedStatement pstmt = con.prepareStatement("insert into bfiles values(?,?)");
                        pstmt.setString(1, fileName);
                        pstmt.setBinaryStream(2, fis, (int)file.length());
                        pstmt.executeUpdate();
                        out.println("Inserted");
                        fis.close();
                        pstmt.close();
                        con.close();
                        out.println("closed");
                   catch(Exception e)
                        out.println(e);
               }     in Oracle bi i have created a table like this :
    CREATE TABLE BFILES
      FILENAME     VARCHAR2(100)                    DEFAULT NULL,
      FILECONTENT  BLOB                             DEFAULT EMPTY_BLOB()
    )Please help me ourt to solve this problem.
    i got struck in this problem.
    its urgent
    thanks in advance
    djshivu

    Hi Shanu.
    Thanks for your help...
    By Using THIN driver also we can insert any files more than 4k and and retrive same. Fallowing codes worked fine for me using thin Driver .
    Following are the 2 programs to write and read.
    we can insert and retrieve any format of files ( jpg, gif, doc, xsl, exe, etc...)
    =======================================================
    // Program to insert files in to table
    import oracle.jdbc.driver.*;
    import oracle.sql.*;
    import java.sql.*;
    import java.io.*;
    import java.awt.image.*;
    import java.awt.*;
    * @author  Shivakumar D.J
    * @version
    public class WriteBlob{
    public static void main(String[] args){
    String filename = "018-Annexure-A.xls";
    Connection conn = null;
    try{
        Class.forName("oracle.jdbc.driver.OracleDriver");
        conn=DriverManager.getConnection("jdbc:oracle:thin:@test:1521:orcl","modelytics","modelytics");
        conn.setAutoCommit(false);
        Statement st = conn.createStatement();
        int b= st.executeUpdate("insert into bfiles values('"+filename+"', empty_blob())");
        ResultSet rs= st.executeQuery("select * from bfiles for update");
        rs.next();
        BLOB blob=((oracle.jdbc.driver.OracleResultSet)rs).getBLOB(2);
        FileInputStream instream = new FileInputStream(filename);
        OutputStream outstream = blob.getBinaryOutputStream();
        int chunk = blob.getChunkSize();
        byte[] buff = new byte[chunk];
        int le;
        while( (le=instream.read(buff)) !=-1)
            outstream.write(buff,0,le);
        instream.close();
        outstream.close();
        conn.commit();
        conn.close();
        conn = null;
        System.out.println("Inserted.....");
       catch(Exception e){
            System.out.println("exception"+e.getMessage());
            e.printStackTrace();
       }//catch
    }=======================
    // Program to retrieve files from database
    [import java.sql.*;
    import java.io.*;
    import java.awt.*;
    public class ReadImage
    public static void main(String a[])
        String fileName ="018-Annexure-A.xls";
        try
              Driver driver = new oracle.jdbc.driver.OracleDriver();
              DriverManager.registerDriver(driver);
              Connection con = DriverManager.getConnection("jdbc:oracle:thin:@test:1521:orcl", "modelytics", "modelytics");
            File file = new File("C:/Documents and Settings/USERID/Desktop/dump.xls");
              FileOutputStream targetFile=  new FileOutputStream(file); // define the output stream
              PreparedStatement pstmt = con.prepareStatement("select filecontent from bfiles where filename= ?");
              pstmt.setString(1, fileName);
               ResultSet rs = pstmt.executeQuery();
               rs.next();
               InputStream is = rs.getBinaryStream(1);
              byte[] buff = new byte[1024];
               int i = 0;
               while ((i = is.read(buff)) != -1) {
                    targetFile.write(buff, 0, i);
                   System.out.println("Completed...");
            is.close();
            targetFile.close();
            pstmt.close();
           con.close();
        catch(Exception e)
              System.out.println(e);
    }====================
    Table Structure is like this
    CREATE TABLE BFILES
      FILENAME     VARCHAR2(100)                    DEFAULT NULL,
      FILECONTENT  BLOB                             DEFAULT EMPTY_BLOB()
    )========================================================
    i hope above codes will helpful for our future programmers
    thanks shanu...
    regards
    djshivu...(javashivu)

  • Uploading data through jdbc thin client appl to database is taking time.

    Hi
    When application team try to upload data (excel file) through JDBC app to the database is taking too much time. When I checked through TOAD below query in background is taking too much time.
    SELECT NULL AS table_cat, t.owner AS table_schem,
    t.table_name AS table_name, t.column_name AS column_name,
    DECODE (t.data_type,
    'CHAR', 1,
    'VARCHAR2', 12,
    'NUMBER', 3,
    'LONG', -1,
    'DATE', 91,
    'RAW', -3,
    'LONG RAW', -4,
    'BLOB', 2004,
    'CLOB', 2005,
    'BFILE', -13,
    'FLOAT', 6,
    'TIMESTAMP(6)', 93,
    'TIMESTAMP(6) WITH TIME ZONE', -101,
    'TIMESTAMP(6) WITH LOCAL TIME ZONE', -102,
    'INTERVAL YEAR(2) TO MONTH', -103,
    'INTERVAL DAY(2) TO SECOND(6)', -104,
    'BINARY_FLOAT', 100,
    'BINARY_DOUBLE', 101,
    1111
    ) AS data_type,
    t.data_type AS type_name,
    DECODE (t.data_precision,
    NULL, t.data_length,
    t.data_precision
    ) AS column_size,
    0 AS buffer_length, t.data_scale AS decimal_digits,
    10 AS num_prec_radix, DECODE (t.nullable, 'N', 0, 1) AS nullable,
    NULL AS remarks, t.data_default AS column_def, 0 AS sql_data_type,
    0 AS sql_datetime_sub, t.data_length AS char_octet_length,
    t.column_id AS ordinal_position,
    DECODE (t.nullable, 'N', 'NO', 'YES') AS is_nullable
    FROM all_tab_columns t
    WHERE t.owner LIKE :1 ESCAPE '/'
    AND t.table_name LIKE :2 ESCAPE '/'
    AND t.column_name LIKE :3 ESCAPE '/'
    ORDER BY table_schem, table_name, ordinal_position
    All other activity on app and database is fine.
    Kindly need a suggestion soon regarding this.
    Thanks
    SHIYAS

    which is easier to read & understand?
    SELECT NULL                                        AS table_cat,
           t.owner                                     AS table_schem,
           t.table_name                                AS table_name,
           t.column_name                               AS column_name,
           Decode (t.data_type, 'CHAR', 1,
                                'VARCHAR2', 12,
                                'NUMBER', 3,
                                'LONG', -1,
                                'DATE', 91,
                                'RAW', -3,
                                'LONG RAW', -4,
                                'BLOB', 2004,
                                'CLOB', 2005,
                                'BFILE', -13,
                                'FLOAT', 6,
                                'TIMESTAMP(6)', 93,
                                'TIMESTAMP(6) WITH TIME ZONE', -101,
                                'TIMESTAMP(6) WITH LOCAL TIME ZONE', -102,
                                'INTERVAL YEAR(2) TO MONTH', -103,
                                'INTERVAL DAY(2) TO SECOND(6)', -104,
                                'BINARY_FLOAT', 100,
                                'BINARY_DOUBLE', 101,
                                1111)                  AS data_type,
           t.data_type                                 AS type_name,
           Decode (t.data_precision, NULL, t.data_length,
                                     t.data_precision) AS column_size,
           0                                           AS buffer_length,
           t.data_scale                                AS decimal_digits,
           10                                          AS num_prec_radix,
           Decode (t.nullable, 'N', 0,
                               1)                      AS nullable,
           NULL                                        AS remarks,
           t.data_default                              AS column_def,
           0                                           AS sql_data_type,
           0                                           AS sql_datetime_sub,
           t.data_length                               AS char_octet_length,
           t.column_id                                 AS ordinal_position,
           Decode (t.nullable, 'N', 'NO',
                               'YES')                  AS is_nullable
    FROM   all_tab_columns t
    WHERE  t.owner LIKE :1 ESCAPE '/'
           AND t.table_name LIKE :2 ESCAPE '/'
           AND t.column_name LIKE :3 ESCAPE '/'
    ORDER  BY table_schem,
              table_name,
              ordinal_position

  • Is it possible to pass blob from java to PL/SQL ?

    Hi, I try to bind a PL/SQL function who return a blob to a java class :
    Signature of java method :
        public static Blob getBLOB(int aId, String aJDBC) {Create PL/SQL function :
    create or replace function aa_java(myPiId in number,myPiJDBC in varchar2) return blob
    as language java
    name 'zip.ReadBLOB.getBLOB(int,java.lang.String) return java.sql.Blob';
    /In java code, my blob has the right size (150 Ko) but in PL/SQL, size = 0 !!!
    Any ideas ?

A: Is it possible to pass blob from java to PL/SQL ?

Thank you, but I think I have a Java problem...
Here is my code :
package zip;
import java.sql.*;
import oracle.jdbc.OracleDriver;
import oracle.sql.BLOB;
public class ReadBLOB {
    public static BLOB getBLOB(int aId, String aJDBC) {
        BLOB vBlob = null;
        try {
            DriverManager.registerDriver(new OracleDriver());
            Connection connection = DriverManager.getConnection(
                aJDBC,
            PreparedStatement stat = connection
                .prepareStatement("select image from aa_blob where id="+aId);
            ResultSet rs = stat.executeQuery();
            if (rs.next()) {
                vBlob = (BLOB) rs.getBlob(1);
                System.out.println("Taille 1 : "+vBlob.length());
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        return vBlob;
    public static void main(String[] args) throws Exception {
        BLOB vBlob = getBLOB(1, "jdbc:oracle:thin:@vdn-ceg5:1521:DEV5");
        System.out.println("Taille 2 : "+vBlob.getLength());
}When I run the main method, I have :
Taille 1 : 150260
Taille 2 : 86
!!!!????!!!!????

Thank you, but I think I have a Java problem...
Here is my code :
package zip;
import java.sql.*;
import oracle.jdbc.OracleDriver;
import oracle.sql.BLOB;
public class ReadBLOB {
    public static BLOB getBLOB(int aId, String aJDBC) {
        BLOB vBlob = null;
        try {
            DriverManager.registerDriver(new OracleDriver());
            Connection connection = DriverManager.getConnection(
                aJDBC,
            PreparedStatement stat = connection
                .prepareStatement("select image from aa_blob where id="+aId);
            ResultSet rs = stat.executeQuery();
            if (rs.next()) {
                vBlob = (BLOB) rs.getBlob(1);
                System.out.println("Taille 1 : "+vBlob.length());
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        return vBlob;
    public static void main(String[] args) throws Exception {
        BLOB vBlob = getBLOB(1, "jdbc:oracle:thin:@vdn-ceg5:1521:DEV5");
        System.out.println("Taille 2 : "+vBlob.getLength());
}When I run the main method, I have :
Taille 1 : 150260
Taille 2 : 86
!!!!????!!!!????

  • Retrieving LOB Storage Parameter through jdbc

    Is there a way to retrieve the lob column's initial and next storage parameter through jdbc?
    I need to replicate a table in one database to another database and with tables containing lobs(clobs,blobs),
    I need to get the storage parameter values for creating a "Create Table" script on the other database.
    tnx

    In records.jsp change your line that reads:
    out.print("<a href =vdetails.jsp>" +  plantno);Change it to:
    out.print("<a href =vdetails.jsp?plantno=" + plantno + ">" +  plantno);Then you can change your line in vdetails.jsp:
    String pla=request.getParameter("something");to
    String pla=request.getParameter("plantno");That should be enough to get you started.
    You should investigate either the use of a bean or even a custom tag to remove these scriplets from your JSP.

  • Does my MacBook passes audio through Mini Display Port or not?

    I recently bought a Mini DisplayPort > HDMI adapter in order to display my MacBook on my TV. Other users of the same adapter publicly stated that they got video AND audio out, but I got only video.
    I've been searching this online for two days now and I still don't know why (I even searched this support forum, but I must admit that I got a little lost and decided to write my own topic). All I discovered was that some MacBooks have this capacity (to port audio along with video through Mini DisplayPort) and others don't.
    I'm using a white MacBook unibody bought new and latest on late 2009. It's the first model with multitouch trackpad and without FireWire port. Its model name is "MacBook 6,1", I guess.
    Does anybody know for sure if It CAN, in fact deliver audio+video through the Mini DisplayPort if I'm using a compatible HDMI adapter?
    Thanks.

    These models pass audio through the display port:
    iMac (Late 2009), MacBook Pro (Mid 2010), MacBook (Mid 2010), and Mac mini (Mid 2010) supply multichannel audio (up to 8 channels) and video signals over Mini DisplayPort. To connect your television or other HDMI devices to your Mac, use select third-party Mini DisplayPort to HDMI adapters that conform to the VESA v1.1a DisplayPort Interoperability Guidelines. The following adapters adhere to these standards:
    - Moshi Mini DP to HDMI Adapter with Audio Support
    - Griffin Video Display Converter (Mini DisplayPort to HDMI and DVI)

  • How can i put a file into blob using jdbc !?

    Hi
    i tried to put a file into blob , but got a problem.....
    My environment:windows 2000pro,JBuilder 5.0 enterprise,oracle 8.1.6,(not install oracle jdbc driver )
    a part of program(my program is very uglily,if anyone want,later i paste it ba....~_~)
    //Statement stmt2=null;
    //Resultset rs2;
    //opa1 is the blob data
    void saveBlobTableToDisk(Connection con) {
    try {
    stmt2=con.createStatement();
    sqlStr2="SELECT * FROM emp3 where id=1004";
    rs2=stmt2.executeQuery(sqlStr2);
    while (rs2.next()) {
    Blob aBlob=rs2.getBlob("opa1");
    i got the exception :
    " null
    java.lang.UnsupportedOperationException
         at sun.jdbc.odbc.JdbcOdbcResultSet.getBlob(JdbcOdbcResultSet.java:4174)
         at test3.Frame1.saveBlobTableToDisk(Frame1.java:48)
         at test3.Frame1.<init>(Frame1.java:26)
         at test3.Application1.<init>(Application1.java:5)
         at test3.Application1.main(Application1.java:8) "
    and the windows pop up a messagebox said that(about) my memory "0x09af007f" could not read, error in javaw.exe .
    Later i used (ResultSet)getBinaryStream() to solve it. but getBinaryStream() only return a InputStream,so that i can make blob to a file,but i can't make a file to blob using jdbc.....
    I am very stupid that installing sun java, oracle jdbc driver etc....(because i must set a lot of thing such as classpath,java_home etc), Can i only use JBuilder to do that ?
    Or i must install oracle jdbc driver ?
    Thanks.
    D.T.

    My guess here is that Sun's JDBC-ODBC bridge doesn't handle the BLOB datatype. Most ODBC drivers don't support that datatype, so I wouldn't expect the bridge to.
    Is there a reason that you can't use the Oracle driver?
    Justin

  • Pass parameter through standard page "import xml content and actions"

    Dear Portal experts,
    As you know, a standard portal page is configured to allow the import of XML file. It is located in the portal in the path system admin -> transport -> xml content and actions -> import
    I configured a quick link u201Cimportu201D to the page so now the link http://myserver:port/irj/portal/import allows me to access directly to this screen.
    What I would like to do now is to pass the parameter related to u201Cfile nameu201D through this screen meaning that I would like that http://myserver:port/irj/portal/ import/filename=C:\test.xml  fills automatically the fields u201CXML fileu201D with  C:\test.xml 
    Please do you know how to achieve this ?
    Thank you very much and regards

    hi,
    @Maksim :
    When user launch an URL like http://myserver:port/irj/portal/ import/*filename=C:\test.xml, he is requested to provide username and password; as this link is a shortcut for the upload xml page, there is a check of authorization and only portal admin that have authorization and permission on this page/iview will be able to upload xml file through the URL. Hope this clarify.
    @Kumar :
    thank you for your answer. What a pity to not be able to pass parameter through standard portal page/iview particularly knowing that we can pass paramater through many kinds of iviews (transactional iview, url iview, VC iview...). I explored some option on file com.sap.portal.ivs.init.par but this was unsuccessful. However, thanks to this [link bellow|http://wiki.sdn.sap.com/wiki/display/Snippets/ComponenttouploadXMLfilewithPCD+objects], I was able to upload through URL the XML file.
    The problem is that I can upload only XML file that are stored in the server not in the local user computer. My requirement is to be able to upload local XML file stored on user's computer.
    If someone could provide and idea/solution, I would be very grateful.
    Cheers

  • Date & time in sql through jdbc URGENT!!!

    hi,
    How do I enter date & time in this format "16 MAR 2002 12:54:23 pm" in the database of oracle through jdbc-sql?
    Please help me out.
    Its urgent.
    Regards
    Deepa Datar

    If you are familiar with Oracle, you can use PL/SQL to do the work for you. I didn't test this, but it's probably pretty close.
    String sql = "INSERT INTO TBLA
    VALUES(TO_DATE('16 MAR 2002 12:54:23 P.M.','DD MON YYYY HH24:MI:SS P.M.'))";
    I'm assuming that you know how to insert data, you are only wondering about the specifics of dates?
    This can also be done using a prepared statement. You would code the insert statement something like this:
    String sql = "INSERT INTO TBLA
    VALUES(TO_DATE(?,'DD MON YYYY HH24:MI:SS P.M.'))";
    I would suggest that if you can convert the time military (24 hour) time, it is easier to handle. The data format model for this is HH24. Otherwise you will need two prepared statements, one for A.M. and one for P.M.
    Good luck.

  • Relational queries through JDBC with the help of Kodo's metadata for O/R mapping

    Due to JDOQL's limitations (inability to express joins, when relationships
    are not modeled as object references), I find myself needing to drop down to
    expressing some queries in SQL through JDBC. However, I still want my Java
    code to remain independent of the O/R mapping. I would like to be able to
    formulate the SQL without hardcoding any knowledge of the relational table
    and column names, by using Kodo's metadata. After poking around the Kodo
    Javadocs, it appears as though the relevant calls are as follows:
    ClassMetaData cmd = ClassMetaData.getInstance(MyPCObject.class, pm);
    FieldMetaData fmd = cmd.getDeclaredField( "myField" );
    PersistenceManagerFactory pmf = pm.getPersistenceManagerFactory();
    JDBCConfiguration conf = (JDBCConfiguration)
    ((EEPersistenceManagerFactory)pmf).getConfiguration();
    ClassResolver resolver = pm.getClassResolver(MyPCObject.class);
    Connector connector = new PersistenceManagerConnector(
    (PersistenceManagerImpl) pm );
    DBDictionary dict = conf.getDictionary( connector );
    FieldMapping fm = ClassMapping.getFieldMapping(fmd, conf, resolver, dict);
    Column[] cols = fm.getDataColumns();
    Does that look about right?
    Here's what I'm trying to do:
    class Foo
    String name; // application identity
    String bar; // foreign key to Bar
    class Bar
    String name; // application identity
    int weight;
    Let's say I want to query for all Foo instances for which its bar.weight >
    100. Clearly this is trivial to do in JDOQL, if Foo.bar is an object
    reference to Bar. But there are frequently good reasons for modeling
    relationships as above, for example when Foo and Bar are DTOs exposed by the
    remote interface of an EJB. (Yeah, yeah, I'm lazy, using my
    PersistenceCapable classes as both the DAOs and the DTOs.) But I still want
    to do queries that navigate the relationship; it would be nice to do it in
    JDOQL directly. I will also want to do other weird-ass queries that would
    definitely only be expressible in SQL. Hence, I'll need Kodo's O/R mapping
    metadata.
    Is there anything terribly flawed with this logic?
    Ben

    I have a one point before I get to this:
    There is nothing wrong with using PC instances as both DAO and DTO
    objects. In fact, I strongly recommend this for most J2EE/JDO design.
    However, there should be no need to expose the foreign key values... use
    application identity to quickly reconstitute an object id (which can in
    turn find the persistent version), or like the j2ee tutorial, store the
    object id in some form (Object or String) and use that to re-find the
    matching persistent instance at the EJB tier.
    Otherwise, there is a much easier way of finding ClassMapping instances
    and in turn FieldMapping instances (see ClassMapping.getInstance () in
    the JavaDocs).
    Ben Eng wrote:
    Due to JDOQL's limitations (inability to express joins, when relationships
    are not modeled as object references), I find myself needing to drop down to
    expressing some queries in SQL through JDBC. However, I still want my Java
    code to remain independent of the O/R mapping. I would like to be able to
    formulate the SQL without hardcoding any knowledge of the relational table
    and column names, by using Kodo's metadata. After poking around the Kodo
    Javadocs, it appears as though the relevant calls are as follows:
    ClassMetaData cmd = ClassMetaData.getInstance(MyPCObject.class, pm);
    FieldMetaData fmd = cmd.getDeclaredField( "myField" );
    PersistenceManagerFactory pmf = pm.getPersistenceManagerFactory();
    JDBCConfiguration conf = (JDBCConfiguration)
    ((EEPersistenceManagerFactory)pmf).getConfiguration();
    ClassResolver resolver = pm.getClassResolver(MyPCObject.class);
    Connector connector = new PersistenceManagerConnector(
    (PersistenceManagerImpl) pm );
    DBDictionary dict = conf.getDictionary( connector );
    FieldMapping fm = ClassMapping.getFieldMapping(fmd, conf, resolver, dict);
    Column[] cols = fm.getDataColumns();
    Does that look about right?
    Here's what I'm trying to do:
    class Foo
    String name; // application identity
    String bar; // foreign key to Bar
    class Bar
    String name; // application identity
    int weight;
    Let's say I want to query for all Foo instances for which its bar.weight >
    100. Clearly this is trivial to do in JDOQL, if Foo.bar is an object
    reference to Bar. But there are frequently good reasons for modeling
    relationships as above, for example when Foo and Bar are DTOs exposed by the
    remote interface of an EJB. (Yeah, yeah, I'm lazy, using my
    PersistenceCapable classes as both the DAOs and the DTOs.) But I still want
    to do queries that navigate the relationship; it would be nice to do it in
    JDOQL directly. I will also want to do other weird-ass queries that would
    definitely only be expressible in SQL. Hence, I'll need Kodo's O/R mapping
    metadata.
    Is there anything terribly flawed with this logic?
    Ben
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • How to save Chinese&Japanise Character through JDBC or Hibernate in ORACLE

    Dear all,
    How to save chinese and japanise character in oracle 9i database through JDBC or Hibernate.
    Please let us know if you have any source code.
    Thanks in advance.
    Thanks,
    Sundararaman.V.S.

    http://forums.oracle.com/forums/ann.jspa?annID=599
    C.

  • Calling Stored Procedures through JDBC

    Hello!
    I would like to implement a call to a stored procedure through JDBC. This call I suppose to embed in JavaBean to import Bean as model.
      A) Shoud this call be implemented inside ordinaly JavaBean or inside EJB?
      B) How can I determine DataSource? Is it possible through JNDI?
      C) Is there any tutorials or examples?
      D) Could anybody give some code texts on this theme?

    we use quite a similar architecture here (2 ORACLE DBs, a DB link from one instance to the other). However, we use the db links in functions (not in stored procedures). but a simple select using the db link also works with JDBC. do you use the very same db instances / schemas / users+passwords on all your different test environments? so far, we havent' noticed any problems with ORACLE queries (stored procedures, functions, etc.) that work in sqlplus/worksheet but not with JDBC. do you use the latest ORACLE JDBC drivers (9.2.0.3)?

  • How to connect informix database from informatica through JDBC instead of ODBC

    How to connect informix database from informatica through JDBC instead of ODBC.

    Hi mate,
    You may get fast reply for this in informatica forums.
    Thanks
    http://mkashu.blogspot.com

  • Inserting ordimage in database through jdbc

    I want to insert an image of type ordimage to database through jdbc but not finding to which jdbc type i should map this when setting parameter in callableStatement. Kindly help me.

    Hi,
    There is a [url http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10779/toc.htm]specific Java API for the multimedia types (of which ORDIMAGE is one).
    John

  • Problem with delete command through JDBC

    hi all,
    I have the following code in a Java program
    try
    DriverManager.registerDriver
    (new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "airport", "airport");
    catch (SQLException ex)
    ex.printStackTrace();
    Every statement works fine except the delete command. When i try to execute this statement:
    stmt = conn.createStatement();
    stmt.executeUpdate("DELETE FROM distances");
    the program stalls. The table "distances" is owned by the user airport and this sql command works fine when I execute it in SQL+. The problem occurs when I try to execute a delete command through JDBC.
    Can anyone help me?
    Thanks...

    It seems that the problem ocuurs only when there are pending transactions.Correct. There are uncommitted INSERT/UPDATE/DELETEs on the table. Readers never block writers, thus having opened SELECT cursors on the table is not a problem. You writer process must be blocked by another writer process. (assuming of course no JDBC thin driver error - of which I've heard rumours there are or were quite a few - not using thin JDBC myself, thus cannot comment on whether these rumours are valid or not)
    What I would think a bit concerning is that one application trashing a table (deleting all the data) while other applications/users are busy changing data in that table. Why are they changing data that will be immediately trashed after they have committed their transactions? Surely they are wasting time and resources all around (user-side and server-side) by doing work that will be immediately invalidated? This kind of points to me to a database or application design problem.

  • Maybe you are looking for

    • HP Laserjet P4014 tray 1 printing problems

      We have three HP Laserjet P4014 printers.  All of them are having intermittent issues with printing from Tray1 especially if the printer has been left for a time. Sometimes if paper is in tray 1 it will not take the paper from this tray only tray2. 

    • Why is there no auto-bookmarking for playlists?

      I have read many requests for better iPod bookmarking capabilities. I am amazed there are no good answers. The only half-baked solutions I have seen are buying multiple iPods or manually converting mp3 and m4a to m4b files. I have filled my iPod with

    • The entry FBZ4 S  is missing in table T021V

      HI I am doing the service tax thorugh f-58 , there i am geeting this error. The entry FBZ4 S  is missing in table T021V.

    • DW cs3 help files not installed

      DW CS3 F1 does not work. . . files not installed. Am I missing something? I began to reinstall dw but did not see a custom or options so I backed out. Any ideas?

    • It won't open

      When I upgraded to iTunes 6.0, everything installs fine. When I try to open iTunes, it does nothing. It won't open.