Oracle spatial new driver add record instance

Source: Internet
Author: User

Oracle's spatial database operation driver updated, the new driver for Oracle8.0 or above, the new driver in the database operation above and the original driver difference is larger, but one thing: the use of simple
The steps to build a spatial database and to create a spatial index are skipped, and there are many examples on the web, and the implementation is unchanged, and the following list of code to add a space database record:

Import java.sql.*;
Import oracle.sql.*;
Import Oracle.spatial.geometry.JGeometry;

/**
* <p>title: </p>
*
* <p>description: </p>
*
* <p>copyright:copyright (c) 2006</p>
*
* <p>company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Sdoadd {
public static void Main (string[] args) {
String Driver = "Oracle.jdbc.driver.OracleDriver";
String url = "Jdbc:oracle:thin:@172.16.75.200:1521:starmap";
String uid = "Hmbst";
String PSW = "Hmbst";
Connection conn = null;
PreparedStatement Ps=null;
try {
Class.forName (driver);
conn = drivermanager.getconnection (URL, uid, PSW);

Jgeometry jgeometry=new jgeometry (41884696,14377039,0);
STRUCT obj =jgeometry.store (jgeometry,conn);
String sql =
"INSERT into POISDO values (Seq_poi_id.nextval,?,?)";
PS = Conn.preparestatement (sql,resultset.type_scroll_insensitive, resultset.concur_updatable);
Ps.clearparameters ();
Ps.setstring (1, "my Home");
Ps.setobject (2, obj);
Insert Point object Record
Ps.executeupdate ();
Conn.commit ();
}
catch (Exception ex) {
Ex.printstacktrace ();
}
Finally
{
if (conn!=null)
{
try {
Conn.close ();
}
catch (SQLException ex) {
Ex.printstacktrace ();
}
}
if (ps!=null)
{
try {
Ps.close ();
}
catch (SQLException ex) {
Ex.printstacktrace ();
}
}

}
}
}

The structure of table poisdo is as follows

create table poi (
id INTEGER,
gname VARCHAR2(256),
gshape MDSYS.SDO_GEOMETRY);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.