public void Modify() { Connection con=null; try { Class.forName("com.mysql.jdbc.Driver"); con= DriverManager.getConnection("jdbc:mysql://localhost:3306/newsmanager","root","000000"); Statement st= con.createStatement(); boolean flag=st.execute("update tb_theme set tname='helloworld' where tid=1"); System.out.println(flag); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }finally{ try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } }
boolean execute()
throws SQLException在此 PreparedStatement 对象中执行 SQL 语句,该语句可以是任何种类的 SQL 语句。一些特别处理过的语句返回多个结果,execute 方法处理这些复杂的语句,executeQuery 和 executeUpdate 处理形式更简单的语句。
execute 方法返回一个 boolean 值,以指示第一个结果的形式。必须调用 getResultSet 或 getUpdateCount 方法来检索结果,并且必须调用 getMoreResults 移动到任何后面的结果。
返回:
如果第一个结果是 ResultSet 对象,则返回 true;如果第一个结果是更新计数或者没有结果,则返回 false