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();请问是第一种写法更好吗,想知道下问什么。是因为内存分配的空间少吗?
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();请问是第一种写法更好吗,想知道下问什么。是因为内存分配的空间少吗?
解决方案 »
- java的垃圾回收机制是完全不可控的,但调用System.gc()后不就会清理内存了吗
- 怎样用字节数组在本地文件系统生成图像
- Java中利用二维数组存储输入字符串问题
- 收索Java俄罗斯方块的源程序!有的朋友放上去谢谢哦
- 不懂啊,帮帮忙啊,哥哥们
- (java.util.Date)(session.getAttribute("date")不报错的问题
- 我郁闷死了,我觉得没问题的东西,却一直提示错误,希望大哥们,来看看呀~~~
- BigInteger转成String然后转成char[ ]后,输出的是内存地址,怎么样才能正常输出呢?
- 《Java就业培训教程》为什么敢叫板“就业”!!
- int与integer的使用
- 希望工作经验久的老鸟解惑
- for ( i=0,j=s.length-1;i<=j; i++,j--) 初学这个语句不明白,等同什么
在内存空间中我们是通过变量名来操作内存空间的,每个变量名又单独
标识自己的内存空间。你想一想如果因为内容一样就用同一个内存空间
那岂不是说一个内存空间有两个不同的变量名同时标志了?那如果改变
其中一个的数据,那另一个不是也随之改变了?你觉得科学吗?
再想想,如果我们定义public int i = 2; private int j = 2;
它们内容一样,你能说i和j就是一样的吗?
没关系的,他的connection关闭了。
当然,随时记得关闭statement对象是个好习惯,会避免不必要的麻烦。
除此之外还是喜欢第一种写法。