for Ex:
class sample { public static void main(String a[]) { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:orcl", "", ""); String str = "Slect * from EMP"; Statement st = con.createStatement(); try { st.executeUpdate("select * from EMP"); //gives us Exception } catch(SQLException ex) { // I want actuval code here.......... //CODE here............ }//catch}//try}//main}//class推荐答案
正如其他人所指出的: executeUpdate()不能用于运行查询。
As others have pointed out: executeUpdate() can not be used to run queries.
如果您正在寻找一种执行语句而不知道它们是什么的方法,那么您应该看一下execute()方法。 http: //download.oracle/javase/6/docs/api/java/sql/Statement.html#execute%28java.lang.String%29
If you are looking for a way to execute statement without knowing what they do, you should have a look at the execute() method. download.oracle/javase/6/docs/api/java/sql/Statement.html#execute%28java.lang.String%29
返回的布尔值将告诉您它是返回结果还是更新计数。然后,您可以使用getResultSet()来获取结果,或使用getUpdateCount()来获取受影响的行数。
The returned boolean will tell you if it returned a result or just update counts. You can then use getResultSet() to obtain the result or getUpdateCount() to get number of affected rows.
请注意,允许语句返回多个结果和/或udpate计数。请参阅getMoreResults()中的示例。
Note that a statement is allowed to return more than one result and/or udpate count. See the example in getMoreResults().
更多推荐
使用executeUpdate()而不是executeQuery()进行SELECT查询
发布评论