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()
不能用于运行查询。
如果您正在寻找一种执行语句而不知道它们做什么的方法,您应该看看execute() 方法。
http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#execute%28java.lang.String%29
返回的布尔值将告诉您它是返回结果还是只是更新计数。然后,您可以使用 getResultSet() 获取结果或使用 getUpdateCount() 获取受影响的行数。
请注意,一条语句允许返回多个结果和/或更新计数。请参阅 getMoreResults() 中的示例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)