熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

使用java調用timesten實現Oracle入庫

2022-06-13   來源: Java核心技術 

  要安裝好timesten

  需要配好system dsn ttdemo

  創建表和存儲過程

  以上略

  java內容如下

  package com;

  import javasqlConnection;

  import javasqlPreparedStatement;

  import javasqlDriverManager;

  import javasqlResultSet;

  import javasqlStatement;

  import javaxsqlrowset*;

  import comsunrowsetCachedRowSetImpl;

  import comtimestenjdbcTimesTenDataSource;

  public class Test {

  public static void main(String arg[]) {

  try {

  //ClassforName(oraclejdbcdriverOracleDriver);

  ClassforName(comtimestenjdbcTimesTenDriver);

  String url = jdbc:timesten:direct:dsn=ttdemo;uid=logstat;pwd=logstat;ORACLEID=logstat_;OraclePWD=logstat;

  TimesTenDataSource ds = new TimesTenDataSource();

  dssetUrl(url);

  Connection con = dsgetConnection();

  consetAutoCommit(false);

  PreparedStatement pstmt = null;

  String sql = {call p_insert(??)};

  pstmt = conprepareCall(sql);

  pstmtsetInt();

  pstmtsetString( Test timesten using procerure!);

  pstmtexecuteUpdate();

  mit();

  consetAutoCommit(true);

  conclose();

  } catch (Exception e) {

  Systemoutprintln(etoString());

  }

  }

  }

  備注在使用timesten實現文章提到的批量入庫就會出現錯誤

  javalangClassCastException: comtimestenjdbcJdbcOdbcConnection

  at oraclesqlArrayDescriptorcreateDescriptor(ArrayDescriptorjava:)

  at oraclesqlArrayDescriptorcreateDescriptor(ArrayDescriptorjava:)

  at comTestmain(Testjava:)

  由於java水平太差不好解決記錄於此


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26411.html
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.