看过的东西忘得太快,即便记住,真正用上了才发现记的东西模棱两可。
今天用jdbc写了一段SQL语句,用PreparedStatement对象来插入对象,用pstmt.execute()的执行结果来判断数据是否插入成功:
测试的时候发现,数据明明插入成功,但是execute()的返回却是false :cry: ,晕了。
网上查了API才发现,对execute()返回的true、false的理解真是想当然了~ 8)
参考网址:
[url]http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html[/url]
今天用jdbc写了一段SQL语句,用PreparedStatement对象来插入对象,用pstmt.execute()的执行结果来判断数据是否插入成功:
pstmt = conn.prepareStatement("insert into columninfo(columntitle,reid,topid) values(?,?,?)");
pstmt.setString(1, column.getColumntitle());
pstmt.setInt(2, column.getReid());
pstmt.setInt(3, column.getTopid());
return pstmt.execute();
测试的时候发现,数据明明插入成功,但是execute()的返回却是false :cry: ,晕了。
网上查了API才发现,对execute()返回的true、false的理解真是想当然了~ 8)
public ResultSet executeQuery() throws SQLException
返回一个不为空的结果集
public int executeUpdate() throws SQLException
返回:1、返回INSERT、UPDATE或者DELETE语句执行后的更新行数;
2、返回0表示SQL语句没有执行成功。
public boolean execute() throws SQLException
返回:true表示SQL语句执行的结果返回ResultSet对象;
false表示SQL语句执行结果返回的是更新行数或者没有返回。
参考网址:
[url]http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html[/url]