Topic: java.sql.Statement |
Print this page |
1.java.sql.Statement | Copy to clipboard |
Posted by: jam Posted on: 2003-05-12 15:27 Who can help me? Thanks When we use int result = java.sql.Statement.executeUpdate("update table....."); or int[] results = java.sql.Statement.executeBatch(); if without exception, int result will be 1, 0 ....... result means ??? and if without exception, int[] results will be 1, 0 ....... results means ??? Is it correct of attach image ? If yes, result = 1 (update table data), means "CLOSE_CURRENT_RESULT" or "RETURN_GENERATED_KEYS" (缩略图,点击图片链接看原图) |
2.Re:java.sql.Statement [Re: jam] | Copy to clipboard |
Posted by: why Posted on: 2003-05-13 00:30 I don't know what you're looking at those ints are the "update counts", which should be clear enough on the API doc: http://java.sun.com/j2se/1.4.1/docs/api/java/sql/Statement.html public int executeUpdate(String sql) throws SQLException Returns: either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing public int[] executeBatch() throws SQLException Returns: an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch. |
3.Re:java.sql.Statement [Re: jam] | Copy to clipboard |
Posted by: jam Posted on: 2003-05-13 09:46 In my testing. public int executeUpdate(String sql) throws SQLException Insert, update, delete If success return >0, If failure return 0 return value means row count public int[] executeBatch() throws SQLException It return int[], the ints are all "-2". return "-2" means what. The gif is at java.sql.Statement -> Field Summary -> Constant Field Values , you will get it. (缩略图,点击图片链接看原图) |
4.Re:java.sql.Statement [Re: jam] | Copy to clipboard |
Posted by: why Posted on: 2003-05-13 10:10 http://java.sun.com/j2se/1.4.1/docs/api/java/sql/Statement.html#executeBatch() public int[] executeBatch() throws SQLException Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following: 1. A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution 2. A value of SUCCESS_NO_INFO -- indicates that the command was processed successfully but that the number of rows affected is unknown If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following: 3. A value of EXECUTE_FAILED -- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails As of JDK1.4, SUCCESS_NO_INFO is -2 EXECUTE_FAILED is -3 http://java.sun.com/j2se/1.4.1/docs/api/constant-values.html#java.sql java.sql.Statement public static final int CLOSE_ALL_RESULTS 3 public static final int CLOSE_CURRENT_RESULT 1 public static final int EXECUTE_FAILED -3 public static final int KEEP_CURRENT_RESULT 2 public static final int NO_GENERATED_KEYS 2 public static final int RETURN_GENERATED_KEYS 1 public static final int SUCCESS_NO_INFO -2 |
5.Re:java.sql.Statement [Re: why] | Copy to clipboard |
Posted by: jam Posted on: 2003-05-13 13:47 Thanks Why. You are God. I am not sure of "public int[] executeBatch() throws SQLException" When I update 5 records data using public int executeUpdate(String sql) throws SQLException result is => 1, 1, 0, 1, 1 using public int[] executeBatch() throws SQLException int[5] = {-2,-2,-2,-2,-2}; record 3, ( condition can not find) is 0 of using executeUpdate() |
6.Re:java.sql.Statement [Re: jam] | Copy to clipboard |
Posted by: why Posted on: 2003-05-13 19:51 it simply indicates that the JDBC driver you're using doesn't return the number of rows affected in batch mode. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |