1.String sql = "delete from contract where contractId= ?";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1,contractId);
stmt.executeUpdate();
sql= "delete from customer where contractId= ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1,contractId); stmt.executeUpdate();
stmt.close();
conn.close();2.String sql_1 = "delete from contract where contractId= ?";
PreparedStatement stmt_1 = conn.prepareStatement(sql_1);
stmt_1.setString(1,contractId);
stmt_1.executeUpdate();
stmt_1.close(); String sql_2= "delete from customer where contractId= ?";
PreparedStatement stmt_2 = conn.prepareStatement(sql_2);
stmt_2.setString(1,contractId);
stmt_2.executeUpdate();
stmt_2.close(); conn.close();请问是第一种写法更好吗,想知道下问什么。是因为内存分配的空间少吗?SQL
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1,contractId);
stmt.executeUpdate();
sql= "delete from customer where contractId= ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1,contractId); stmt.executeUpdate();
stmt.close();
conn.close();2.String sql_1 = "delete from contract where contractId= ?";
PreparedStatement stmt_1 = conn.prepareStatement(sql_1);
stmt_1.setString(1,contractId);
stmt_1.executeUpdate();
stmt_1.close(); String sql_2= "delete from customer where contractId= ?";
PreparedStatement stmt_2 = conn.prepareStatement(sql_2);
stmt_2.setString(1,contractId);
stmt_2.executeUpdate();
stmt_2.close(); conn.close();请问是第一种写法更好吗,想知道下问什么。是因为内存分配的空间少吗?SQL
第1个,在某些jdbc的实现里头,还可能造成资源泄漏。
你还是稳稳妥妥的用第二个方法吧。