在執行我的代碼,這是爲了處理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();
}
}
我是新來的編碼,我不確定如何解決這個錯誤,所有幫助表示讚賞。謝謝。
什麼是堆棧跟蹤?請在你的問題中加上。 – Smit 2013-03-11 19:13:20
什麼是表格定義和什麼是堆棧跟蹤? – 2013-03-11 19:36:59
你是交織'executeQuery'在你的SQL批處理電話通話中(當你調用'printrows',這看起來不正確,註釋掉'printrow'通話,並再次測試你的代碼。 – Perception 2013-03-11 19:37:07