2013-03-11 81 views
0

在執行我的代碼,這是爲了處理SQL語句在批處理模式下,我得到這個錯誤:如何在PreparedStatement中使用JDBC中的批處理SQL?

ORA-03115: unsupported network datatype or representation

這是代碼,運行時生成的錯誤:

public class Login { 

    public static void main(String args[]) throws SQLException { 
     Connection con = null; 
     PreparedStatement stmt = null; 
     Statement st = null; 
     try { 
      Driver driver = new oracle.jdbc.driver.OracleDriver(); 
      DriverManager.registerDriver(driver); 
      System.out.println("coneecting to the database:"); 
      con = DriverManager.getConnection("url", "user", "pass"); 
      con.setAutoCommit(false); 
      System.out.println("creating statement"); 
      String sql = "insert into shweta values(?,?)"; 
      stmt = con.prepareStatement(sql); 

      printrows(stmt); 

      stmt.setString(1, "love"); 
      stmt.setInt(2, 45); 
      stmt.addBatch(); 

      stmt.setString(1, "kaun"); 
      stmt.setInt(2, 29); 
      stmt.addBatch(); 

      int count[] = st.executeBatch(); 

      con.commit(); 

      printrows(stmt); 

      // printRs(rs); 

      st.close(); 
      stmt.close(); 
      con.close(); 
     } catch (SQLException e) { 
      e.printStackTrace(); 
      try { 
       if (con != null) 
        con.rollback(); 
      } catch (SQLException en) { 
       en.printStackTrace(); 
      } 
     } 

     catch (Exception e) { 
      e.printStackTrace(); 
     } finally { 
      try { 
       if (stmt != null) 
        stmt.close(); 
      } catch (Exception e) { 
      } 
      try { 
       if (con != null) 
        con.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

     } 
     System.out.println("good bye ashish"); 
    } 

    public static void printrows(Statement stmt) throws SQLException { 
     String sql = "select * from shweta"; 
     ResultSet rs = stmt.executeQuery(sql); 

     while (rs.next()) { 
      // Retrieve by column name 

      int age = rs.getInt("age"); 
      String first = rs.getString("auth"); 

      System.out.print(", Age : " + age + "\n"); 
      System.out.print("AUTH :  " + first + "\n"); 

     } 
     System.out.println(); 
    } 
} 

我是新來的編碼,我不確定如何解決這個錯誤,所有幫助表示讚賞。謝謝。

+0

什麼是堆棧跟蹤?請在你的問題中加上。 – Smit 2013-03-11 19:13:20

+0

什麼是表格定義和什麼是堆棧跟蹤? – 2013-03-11 19:36:59

+0

你是交織'executeQuery'在你的SQL批處理電話通話中(當你調用'printrows',這看起來不正確,註釋掉'printrow'通話,並再次測試你的代碼。 – Perception 2013-03-11 19:37:07

回答

0

用戶綁定或限定,或Oracle功能,不受該 異構SQL *網絡連接支持。 升級舊版本的Oracle,然後重試。

+0

在oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1051) \t at oracle.jdbc.driver.T4CPreparedStatement。 executeMaybeDescribe(T4CPreparedStatement.java:854) \t在oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1156) \t在oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1315)(Login.java:92) \t在Login.main(Login.java:22) – ricky 2013-03-12 16:52:05

+0

這是我的堆棧跟蹤 – ricky 2013-03-12 16:52:27

+0

表只有兩列第一位是作者,第二位是年齡 – ricky 2013-03-12 16:56:17

0

聲明ST未初始化 - 在使用則ExecuteBatch。用於插入的語句stmt不應該更改爲在printrows中運行另一個sql。

+0

java.sql。的SQLException:ORA-03115:不支持的網絡數據類型或表示 \t在oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113) \t在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) \t在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) \t在oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:754) \t在oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219) \t在oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:813) – ricky 2013-03-12 16:51:45

0

我找出導致代碼拋出exception.the原因,問題是,我
NT intializing我的語句聲明ST = con.createstatement();由於其 編譯器扔error.we cannt直接傳遞準備語句對象作爲參數來執行查詢。所以任何我們如何使用語句,並通過其引用printrows到參數。