jdbc basic operation,how to insert a long raw data

原创 2006年05月31日 13:47:00

红色标志处非常重要!!!

package packCGDataServer;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;
import ShapeFile.*;
import DbfFile.*;
import ShapeFile.ShapePoint;

public class DBoper {
 public Connection m_conn;

 public String m_userName;

 public String m_passWord;

 public String m_dataSource;

 public String m_serviceName;

 public String m_portName;

 public boolean initConnection() {
  try {

   DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
   java.util.Properties info = new java.util.Properties();
   info.put("user", m_userName);
   info.put("password", m_passWord);
   // specify the connection object
   m_conn = DriverManager.getConnection("jdbc:oracle:thin:@"
     + m_dataSource + ":" + m_portName + ":" + m_serviceName
     + "", info);
   m_conn.setAutoCommit(false);

   return true;
  } catch (Exception e) {
   System.out.print(e.getMessage());
   return false;
  }
 }

 public boolean executeSQL(String exeStr) {

  try {
   if (m_conn.isClosed() == false) {
    try {
     Statement stmt = m_conn.createStatement();
     stmt.execute(exeStr);
     return true;// jdgStr +" succeeded";
    } catch (Exception e) {
     return false;// jdgStr + " failed";
    }

   } else {
    return false;// jdgStr + " failed";
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return false;

 }

 public boolean addPolygonLayerRecords(ShapefileShape[] ccObJ3,
   String layerID) {
  String tabF = CConfigValue.TABF + layerID;
  try {
   if (m_conn.isClosed() == false) {
    try {
     String content;
     for (int i = 0; i < ccObJ3.length; i++) {
      ShapePolygon ccPolygon = (ShapePolygon) ccObJ3[i];
      content = ccObJ3[i].toString();
      byte[] pts = content.getBytes();
      InputStreamReader bais = new InputStreamReader(
        new ByteArrayInputStream(pts));
      PreparedStatement pstmt = m_conn
        .prepareStatement("insert into "
          + tabF
          + " (FID,FIDTYPE,NUMOFCOUNTS,"
          + "MINX,MINY,MAXX,MAXY,AREA,LEN,POINTS,"
          + "CSRID,MSRID,BDELETED,BRELATEDID,BLOCK,PROCID) values (?,?,?,?,?,?,?,?,?,utl_raw.cast_to_raw(?),?,?,?,?,?,?)");
      long v_FID = i + 1;
      long v_FIDTYPE = 1;
      int v_NUMOFCOUNTS = ccPolygon.getNumPoints();
      double v_MINX = ccPolygon.getBounds()[0];
      double v_MINY = ccPolygon.getBounds()[1];
      double v_MAXX = ccPolygon.getBounds()[2];
      double v_MAXY = ccPolygon.getBounds()[3];
      double v_AREA = 0;
      double v_LEN = 0;
      // POINTS
      String v_CSRID = "1";
      String v_MSRID = "1";
      String v_BDELETED = "0";
      String v_BRELATEDID = "0";
      String v_BLOCK = "0";
      String v_PROCID = "0";

      pstmt.setString(1, String.valueOf(v_FID));
      pstmt.setString(2, String.valueOf(v_FIDTYPE));
      pstmt.setString(3, String.valueOf(v_NUMOFCOUNTS));
      pstmt.setString(4, String.valueOf(v_MINX));
      pstmt.setString(5, String.valueOf(v_MINY));
      pstmt.setString(6, String.valueOf(v_MAXX));
      pstmt.setString(7, String.valueOf(v_MAXY));
      pstmt.setString(8, String.valueOf(v_AREA));
      pstmt.setString(9, String.valueOf(v_LEN));
      pstmt.setCharacterStream(10, bais, pts.length);
      pstmt.setString(11, v_CSRID);
      pstmt.setString(12, v_MSRID);
      pstmt.setString(13, v_BDELETED);
      pstmt.setString(14, v_BRELATEDID);
      pstmt.setString(15, v_BLOCK);
      pstmt.setString(16, v_PROCID);

      // pstmt.setString(1, "kitt");
      // pstmt.setCharacterStream(2, bais, pts.length);
      pstmt.execute();
      pstmt.close();
     }
     m_conn.commit();
     return true;// jdgStr +" succeeded";
    } catch (Exception e) {
     return false;// jdgStr + " failed";
    }

   } else {
    return false;// jdgStr + " failed";
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  return false;
 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

How to send raw packet data from Opendaylight controller to network datapath

In this post, two methods are giving to demonstrate how to deliver raw packet-data to network from O...

【MongoDB】The basic operation of Mongodb, Insert\Query\Delete\Update

1, Insert MongoDB is database storing document object, the type of which is called Bs...

Azure Basic - Insert data into BlockBlob, Table and Queue (with Diagnostic + Azure Storage Explore)

Insert data into BlockBlob, Table and Queue Prerequisite Knowledge Blob Storage Queue Storage...

How to set value of Q0000-MASSN in FM HR_INFOTYPE_OPERATION

In fact HR_INFOTYPE_OPERATION is calling HR_MAINTAIN_MASTERDATA(BDC of PA30 actually), and it has a ...

【Hibernate错误解决办法】Could not execute JDBC batch update; Data too long for column 'name' at row 1

刚开始学Hibernate

hdu 4723 How Long Do You Have to Draw(贪心)

How Long Do You Have to Draw Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

hdu4723--(How Long Do You Have to Draw)

题目大意:给出两条平行于x轴的直线,

hdu4723 How Long Do You Have to Draw 贪心

How Long Do You Have to Draw Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

basic_iptables_how_to_for_ubuntu

refer to: https://help.ubuntu.com/community/IptablesHowTo Ubuntu Documentation · Partners  · Suppo...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)