Spatial data through JDBC driver

Hi,
I have a spatial table which has polygon, linestring and points stored in the geometry column. Is there any API available to know whether the stored data is ploygon/point/linestring. I am using thin JDBC driver to connect to Oracle. Also are there APIs available to get the coordiniates, offset etc from polygon. Please let me know if there are any tutorials/examples available for working with spatial data and JDBC driver.
Smitha

Hi,
You could use Oracle Spatial Java Class Library, available at: http://www.oracle.com/technology/software/products/spatial/index.html
It is quite easy to use it.
Regards,
Andrejus

Similar Messages

  • DISPLAY SPATIAL DATA USING JDBC ON A JAVA FRAME

    I am trying to set up some spatial data and need help in getting some sample
    code for displaying the data on a Java Frame using JDBC.
    The shapes I am setting up are simple polygons, lines, circles. I was going
    through the samples in the demo directory under $ORACLE_HOME/md/demo/examples, but could not find any JDBC
    I would really appreciate if you can point me towards some sample code and any other spatial resources.
    Madhukar

    Here you go. It uses JDBC to fetch geoms, convert them into Java JGeometry objects, which then create Java2D shapes (these are functions of the public sdoapi.jar library). It then uses some class in the sdovis.jar library (the rendering engine of MapViewer) to setup the necessary viewport transform. If you know how to setup the viewport transform, then you dont even need sdovis. sdovis.jar is found in an deployed MapViewer's WEB-INF/lib directory. Or you can extract it from the mapviewer.ear's web.war file.
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import oracle.jdbc.OracleDriver;
    import oracle.sdovis.*;
    import oracle.sdovis.style.*;
    import oracle.sdovis.util.*;
    import oracle.spatial.geometry.JGeometry;
    import oracle.sql.STRUCT;
    * A very simple program that shows stuff from db in a JFrame
    * <p>
    public class tilsvgui2 extends JFrame
      final static int mapWidth  = 640;
      final static int mapHeight = 480;
      static JSDOGeometry geom = null;
      public tilsvgui2()
        setSize(mapWidth+40, mapHeight+40);
                    setVisible(true);
        this.addWindowListener(new java.awt.event.WindowAdapter() {
          public void windowClosing(WindowEvent e) { System.exit(0); }
            public void paint(Graphics g)
                    super.paint(g);
        int w = this.getWidth(), h = this.getHeight();
        Insets inset = this.getInsets();
        double[] mbr = geom.getMBR();
        //from sdovis; it will setup the viewport transform
        XFViewPort xfp = new XFViewPort();
        xfp.setDeviceView(inset.left, inset.top, w-inset.left-inset.right-1, h-inset.top-inset.bottom-1);
        xfp.setDataView(mbr[0], mbr[1], mbr[2], mbr[3]);
        AffineTransform af = xfp.getAffineTransform();    //get the viewport transform
        Shape shp = geom.createShape(af);    //create a proper shape that fits the viewport
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.red);
        g2.drawRect(inset.left, inset.top, w-inset.left-inset.right-1, h-inset.top-inset.bottom-1);
        //draw the shape itself
        g2.setColor(Color.blue);
        g2.draw(shp);
      public static void getStuff() throws Exception
        System.out.println("Loading geometry...");
        Connection conn = getConnection("mapsrus.us.oracle.com", "1521", "orcl", "scott", "tiger");
        Statement  stmt = conn.createStatement();
        ResultSet  rset = stmt.executeQuery("select geom, totpop from counties where county='Merrimack' and state_abrv='NH'");
        while(rset.next())
          STRUCT st = (STRUCT) rset.getObject(1);
          geom = JSDOGeometry.loadFromDB(st);
          int population = rset.getInt(2);
          break; //displaying only the first geometry
        rset.close();
        stmt.close();
        conn.close();
      private static Connection getConnection(String host,
                                              String port,
                                              String sid,
                                              String username,
                                              String password)
        throws SQLException
        String thinConn = "jdbc:oracle:thin:@"+host+":"+port+":"+sid;
        Driver d = new OracleDriver();
        Connection conn = DriverManager.getConnection(thinConn,username,password);
        conn.setAutoCommit(false);
        return conn;
      public static void main(String[] args)
        try{
          getStuff();
        }catch(Exception e)
          e.printStackTrace(System.err);
        new tilsvgui2();
    }

  • Acquiring Oracle Spatial Data through WFS

    Hi,
    I have been researching for awhile and am slightly confused.
    I have Oracle Spatial 11g with geometry data and would like to be able to retrieve that data through a WFS to serve to a viewing application.
    Here's where I am confused:
    1) Spatial has a WFS service which needs to be configured. If I were configure that, would I be able to access the data through URL getFeature commands? The documentation I see for them has the getFeature requests in the form of XML files so I am not sure if I can do that. Also it seems like the service is returning .log files but I think I would want GML...
    If this is the option I should take, the tutorial to setup OC4J and the Web Services are for a Linux machine (http://www.oracle.com/technology/obe/11gr1_db/datamgmt/spatialws/spatialws.htm) -- Is there one for Windows 64bit?
    2) Do I need another "application layer" to enable this URL support? I know MapServer can use URL requests.. can I just run this against the data in my DB and forget about the Oracle WFS?
    3) MapViewer seems to work with WFS Themes and handle requests through Java and SQL.. is this another option?
    I am basically confused as to where everything sits and what I should be focusing on to get my Spatial data out of the DB through a WFS. Any assistance on this matter would be greatly appreciated!
    Thanks!

    Any help debugging this issue would be greatly appreciated:
    As per the documentation:
    http://localhost:8888/SpatialWS-SpatialWS-context-root/wfsservlet?request=GetCapabilities&service=wfs&version=1.0.0
    :this get request should return the capabilities info however I receive this error message instead in the browser:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ogc:ServiceExceptionReport version="1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://localhost:8888/examples/servlets/xsds/OGC-exception.xsd" xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:ServiceException code="WFS-1042">Exception during processing request</ogc:ServiceException>
    </ogc:ServiceExceptionReport>
    The sytem out from the oc4j container provides this error message:
    10/04/27 15:47:38 [oracle.spatial.ws.WSProperties, Tue Apr 27 15:47:38 MDT 2010,
    INFO] No subject specified in request.
    10/04/27 15:47:38 [oracle.spatial.ws.WSProperties, Tue Apr 27 15:47:38 MDT 2010,
    ERROR] Oracle Spatial WS Server could not set up configuration parameters: jav
    a.lang.RuntimeException: No subject specified in request.
    10/04/27 15:47:38 [oracle.spatial.ws.servlet.WFSServlet, Tue Apr 27 15:47:38 MDT
    2010, FATAL] java.lang.RuntimeException: java.lang.RuntimeException: No subject
    specified in request.
    at oracle.spatial.ws.WSProperties.getProperties(WSProperties.java:705)
    at oracle.spatial.ws.servlet.WFSServlet.doGet(WFSServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletReque
    stDispatcher.java:734)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(Ser
    vletRequestDispatcher.java:391)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequ
    estHandler.java:908)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpReques
    tHandler.java:458)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpReque
    stHandler.java:226)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
    va:127)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
    va:116)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSo
    cketReadHandler.java:260)
    at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(Server
    SocketAcceptHandler.java:234)
    at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocket
    AcceptHandler.java:29)
    at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(
    ServerSocketAcceptHandler.java:879)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(Relea
    sableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.RuntimeException: No subject specified in request.
    at oracle.spatial.ws.WSProperties.getUser(WSProperties.java:574)
    at oracle.spatial.ws.WSProperties.getProperties(WSProperties.java:695)
    ... 16 more

  • 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

  • Controlling access to Oracle Mapviewer spatial data through VPD

    I am building a web GIS application in Oracle Application Express (APEX) and have used the Virtual Private Database feature of Oracle Database 11g Enterprise Edition so as to ensure row level security. I've integrated APEX with Oracle Mapviewer through Oracle Maps API in order to display a map.
    VPD feature is working properly through the command prompt at the database level but I also need to use the VPD policy at the application level so that each authenticated user can only see his own spatial data on the map.
    So far I have accomplished that by creating as many data sources as the number of application users on the mapViewerConfig.xml file. Every time a user logs in the web GIS application, the correct data source is being employed.
    I was wondering if there is any other parameterised way that I can perform this access control functionality without having to create all these data sources.
    Many thanks in advance.

    Yes you can define a single "secure" MapViewer data source to achieve VPD or make use of your database VPD setup. For more details and how to get the Apex app user to MapViewer and then onto VPD you can check out my blog post here: http://oraclemaps.blogspot.com/2008/09/apex-oracle-maps-and-secure-mapping.html
    hope this helps,
    LJ

  • JDBC Driver not found when connecting to Data Federator XI 3.0 SP3

    Hello,
    I am trying to connect Crystal 2008 to Data Federator however I am getting the Error
    Failed to open connection.
    Details: JDBC Driver not found.
    The JDBC Drivers are installed and working for the Universe Designer, however I am unable to get it working for Crystal. I am using the following connection parameters on Crystal:
    Connection URL: jdbc:datafederator://<<servername>>:3055/<<catalog>>
    Database Classname: com.businessobjects.datafederator.jdbc.DataFederatorDriver
    Any Advice on what I may have missed?

    The issue was solved, thanks to Patric Wan:
    u201CFailed to open the connection. Details: JDBC driver not found.u201D
    This means Data Federator JDBC driver was not added to:
    C:\Program Files\Business Objects\common\<version>\java\CRConfig.xml
    How to connect the Data Federator Server using JDBC?
    1. Retrieve the following files from the machine where Data Federator is installed, from the directory [data-federator-installation-dir]/JdbcDriver/lib.
        - thindriver.jar
        - avalon-framework-4.1.5.jar
        - jacorb.jar
        - log4j-1.2.8.jar
        - logkit-1.2.jar
    2. Copy these files to a directory of your choice ([your-jdbc-driverdirectory]).
    3. Add [your-jdbc-driver-directory]/thindriver.jar to CRConfig.xml   <Add to Classpath tag, you can refer to original sample.CRConfig.xml should be at: C:\Program Files\Business Objects\Common\4.0\java\CRConfig.xml, or search your BOBJ products install to find this file>
    4. URL: jdbc:leselect://<host>[:<port>][/[<catalog>]][[;param-name=value]*]
    Class Name : LeSelect.ThinDriver.ThinDriver
    Edited by: Craig Sander on Feb 12, 2011 8:22 PM

  • Can't load jdbc driver in servlet

    Dear All,
    I have tried to connect to MS SQL SERVER 2000 through JDBC DRIVER FOR
    SQLSERVER. However I receieved an error: can't load jdbc driver class:
    null.
    The following steps were what I did:
    1.Set up SQL Server and create a few tables and users.
    2.Config Server.xml
    Add the following codes in /tomcat/conf/Server.xml
    <Context path="/persistence" docBase="persistence" debug="0"
    reloadable="true">
              <Resource name="jdbc/persistenceDB" auth="Container"
    type="javax.sql.DataSource"/>
              <ResourceParams name="jdbc/PersistenceDB">
                   <Parameter>
                        <name>user</name>
                        <value>kitty</value>
                   </Parameter>
                   <Parameter>
                        <name>password</name>
                        <value>abc</value>
                   </Parameter>
                   <Parameter>
                        <name>driverClassName</name>
                        <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
                   </Parameter>
                   <Parameter>
                        <name>url</name>
    <value>jdbc:microsoft:sqlserver://localhost:1433;databaseName=persistence;selectMethod=cursor;</value>
                   </Parameter>
              </ResourceParams>               
    </Context>
    3.Config my web application's web.xml
    Added the following piece of code in WEB.XML
    <resource-ref>
    <res-ref-name>jdbc/persistenceDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    4.Use Datasource in my code
    package persistence.database;
    import java.sql.*;
    import javax.naming.InitialContext;
    import javax.sql.DataSource;
    import javax.servlet.ServletContext;
    import persistence.*;
    import com.microsoft.jdbcx.sqlserver.*;
    import javax.naming.Context;
    public class DatabaseAuthenticator implements Authenticator {
    private DataSource ds;
    public void init(ServletContext sctx) throws Exception {
    InitialContext init = new InitialContext();
    try{
         Context ctx = (Context) init.lookup("java:/comp/env");
    ds = (DataSource) ctx.lookup("jdbc/persistenceDB");
    } catch (Exception e) { e.printStackTrace();
    public User authenticate(String username, String password)
    throws AuthenticationException, UnknownException {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs;
    try {
    if (ds != null) {System.out.println("Success to get
    datasource");
            } else {System.out.println("Failed");}
    System.out.println(ds.toString());
    try
    conn = ds.getConnection();     
    catch (Exception e)
    e.printStackTrace();
    pstmt = conn.prepareStatement("SELECT user_id " + .........
    5. put msutil.jar, mssqlserver.jar and msbase.jar under /tomcat/common/lib/.
    When I tried to run the program, I receieved an error: can't load jdbc
    driver class: null.
    I've got no idea what's going on.
    Any Suggestion?
    Thanks in advance
    Kitty

    Hi Kitty,
    The connection you're trying to set up points to nothing :
    Connection conn = null;
    So, you receive a complaint that that driver cannot be loaded. Please read
    http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
    download the right database driver and use that. Good luck!
    Wouter van Reeven
    public User authenticate(String username, String
    g password)
    throws AuthenticationException, UnknownException
    ption {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs;

  • Handheld and jdbc driver

    hello,
    i have to develop an application in java for handeld devices .i want to connect my handheld database through jdbc driver with the database on the desktop. .
    so is there any jdbc driver of any database available which can solve this problem.
    or is there any other way to do this?
    hoping a quich reply. thanking u
    its
    abhishek chopra
    ispan technologies

    Hi,
    Better way to connect to a database is using an intermediate JSP or servlet which receives request from client, executes SQL command on database and sends the result to the client. The reason why it is better to use this method is that any change to database will not need change in client code.

  • Setting order of sorting through JDBC

    Hi there, could somebody please advice - we need to change order of sorting in Oracle 10g. We are using JDBC to connect to a database, and it is possible to have different language in the database rather than on the client computer. We found setting environment variable for language (for Unix - 'LANG') solves the problem, but we can't set this variable within our Java application, so we need some way to sspecify order of sorting through JDBC driver or soemthing like that.
    We tried to create proxy JDBC driver and invoke "ALTER SESSION" after connection established, but that doesn't work for us.
    Thanks in advance.

    set NLS_LANG and NLS_SORT on the clientSorry, you mean do something from outside Java application? The thing we are not allowed to set some environment variables or do something else, we can only do something with JDBC driver I guess, or probably something from our Java application.

  • Insert data 32K into a column of type LONG using the oracle server side jdbc driver

    Hi,
    I need to insert data of more than 32k into a
    column of type LONG.
    I use the following code:
    String s = "larger then 32K";
    PreparedStatement pstmt = dbcon.prepareStatement(
    "INSERT INTO TEST (LO) VALUES (?)");
    pstmt.setCharacterStream(1, new StringReader(s), s.length());
    pstmt.executeUpdate();
    dbcon.commit();
    If I use the "standard" oracle thin client driver from classes_12.zip ("jdbc:oracle:thin:@kn7:1521:kn7a") every thing is working fine. But if I use the oracle server side jdbc driver ("jdbc:default:connection:") I get the exception java.sql.SQLException:
    Datasize larger then max. datasize for this type: oracle.jdbc.kprb.KprbDBStatement@50f4f46c
    even if the string s exceeds a length of 32767 bytes.
    I'm afraid it has something to do with the 32K limitation in PL/SQL but in fact we do not use any PL/SQL code in this case.
    What can we do? Using LOB's is not an option because we have client software written in 3rd party 4gl language that is unable to handle LOB's.
    Any idea would be appreciated.
    Thomas Stiegler
    null

    In rdbms 8.1.7 "relnotes" folder, there is a "Readme_JDBC.txt" file (on win nt) stating
    Known Problems/Limitations In This Release
    <entries 1 through 3 omiited for brevity >
    4. The Server-side Internal Driver has the following limitation:
    - Data access for LONG and LONG RAW types is limited to 32K of
    data.

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

  • Jdbc-updating spatial data

    i looked to the next link:
    http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
    I want to update spatial data.To the previous link i found how to update tables but not how to update tables which contain spatial data.For example:
    CREATE TABLE customers (
    customer_id NUMBER,
    last_name VARCHAR2(30),
    first_name VARCHAR2(30),
    street_address VARCHAR2(40),
    city VARCHAR2(30),
    state_province_code VARCHAR2(2),
    postal_code VARCHAR2(9),
    cust_geo_location SDO_GEOMETRY);
    INSERT INTO customers VALUES
    (1001,'Nichols', 'Alexandra',
    '17 Maple Drive', 'Nashua', 'NH','03062',
    SDO_GEOMETRY(2001, 8307,
    SDO_POINT_TYPE (-71.48923,42.72347,NULL), NULL, NULL));
    if i want to update the costumer position (-71.48923,42.72347) how can i do this;;;

    Try posting this to the JDBC forum:
    http://forum.java.sun.com/forum.jspa?forumID=48

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

  • Data Sources error:[Macromedia][SQLServer JDBC Driver]No more data available to read.

    I have just set up the developer edition coldfusion and a standard SQL Server. When trying to set up a datasource i recieve the following error:  [Macromedia][SQLServer JDBC Driver]No more data available to read. I have no clue what this means. I have tried to find some documentation on this but with now luck. Can anyone help?
    Here are some details:
    SQL SERVER CONNECTION MANAGER:
    Trying to connect to a localhost sql server
    I have TCP/IP Enabled
    Dynamic Ports is set to 0 under IP ALL
    127.0.0.1 is enabled and the port is set to 1433
    COLDFUSION ADMIN:
    server: 127.0.0.1
    port 1433
    username/password set to null (using windows authentication)
    Has anyone ran in to this issue?
    Thanks for helping.

    You can use domain credentials with CF.  To do so you've got to create the datasource in Windows.  Then, in ColdFusion you select ODBC mapping and point it to the Windows DS.
    If I recall correctly, there's a switch in SQL 2005 that you've got to flip to allow SA rights to log in from the network.  I could be way off base on that one though.
    You may want to consider creating a new SQL account with its own password and assigning it to your target database (usually, I grant data reader and writer - your app may vary) and use those new credentials in your JDBC mapping in CF.

  • When I get a date field value using the Oracle thin (type 4) JDBC driver...

    ....in 'DD-MMM-YY' format from an Oracle 8i database and pass it in to the java.util.Date() constructor, I get a IllegalArgumentException. This error doesn't occur when I use the type 2 driver, so it is apparently a driver-specific thing. It happens on both Win32 and Linux.
    Has anyone seen this before? Is there a newer version of the Oracle thin (i.e., type 4) driver than is listed here?
    http://web77-02.us.oracle.com/software/tech/java/sqlj_jdbc/content.html
    Thanks,
    Tom
    [email protected]

    Yup, that original post didn't make much sense, did it? Let's try again.
    I've got an EJB app that runs on WebLogic 6.0 (on Solaris in production, on Win2K for development) and accesses an Oracle 8i database. This app currently uses the Oracle type 2 JDBC drivers. All is well.
    So I wanted to see how it would run on Linux. I've got a Redhat 7.1 box handy, so I installed the JDK and WL6.0 and slapped the ear file on there. Problem! Can't deploy because there are no Oracle drivers on this machine!
    Makes sense. So I started looking around, and it seems installing Oracle on a RH 7.1 box involves patching glibc and other such nastiness. So let's just try the type 4 JDBC driver - no glibc patch, no shared object libraries, just good 'ol pure Java talking to Oracle on port 1521.
    Once I had the URLs and whatnot set up, the app connected to the DB just fine, created the connection pool, read some data, etc. But when my app read a date from the DB and instantiates a new java.util.Date object, I got an IllegalArgumentException - i.e., the date can't be parsed.
    "Hmm... that's odd", I thought, so back I went to my trusty Win2K machine, modified my configuration files to use the type 4 driver and - same error! So I switched back to the type 2 driver - and everything works fine, Dates and all. Hmmm.....
    As you correctly state, that Date constructor is deprecated and I should use DateFormats and GregorianCalendars and whatnot instead.
    But has anyone seen this weird behavior before - code that works fine on a type 2 driver starts throwing exceptions when used with a type 4 driver? Anyone have any solutions?
    Thanks much,
    Tom

Maybe you are looking for

  • How do I undo an app update on macbook pro?

    I updated my iMovie but don't like it and would like to undo the update to the older version again. How do I do that?

  • OS X Lion wont boot

    hi all I have the following problem, I want to install OS X on my macbook pro Lion (Core 2 Duo 2.16 GHz 3GB RAM) in a clean, burn the dmg on a usb, but does not load the operating system stays at the gray screen and Apple logo and no progress, it is

  • Xserve and high end graphic cards?!

    anybody tried to put a new graphic card (like ati 850xt or similar with 256 memory) into a xserve?? could it work? i want to use xserve as desktop machine with gb ram on photoshop... so i need as well a high end graphic card ... any suggestions?

  • Knowing where the call to?

    Hi experts, I got 1 secretary who support 3 users. She's asking on how to know on the Ip Phone unit (7960) for whose call when a missed call has been received by her or whose call is that for? Is there a way what is the original called number on the

  • Regarding physcial inventory

    Hi All , When I am posting the difference with tcode MI07 , I am getting the error "Reason 0002 for movement type 702 not defined". When same I am trying with tcode MI20 , I am not getting this error. Could you please tell me how to eliminate this er