db.update(sql);这语句之前不需要调用db.closeStm(),因为第二次的stm会覆盖掉第一次的stm。你运行一下或者写个test测试一下就知道了
解决方案 »
- 在jsp页面里,点击按钮的时候,怎么把页面上的值保存到数据库中?
- http status 404 错误,急救!!!help
- 如何用java调用cmd.exe,在线等!
- 新手求助!解决代码同一时间只能一个用户访问的问题!可否用 Thread ?????????
- tomcat报答500错误,高手帮我看看
- 关于PreparedStatement的问题
- 那位大虾,做过门户网的,我听说门户网都有可以自动生成html的软件系统,请详细说一下,感谢不禁,不够加分
- JAVAWEB网站开发,一对多,多对一,主表与子表(主外键)相连接,会导致主表字段在JSP页面重复出现
- 希望做到右键点击弹出一个菜单,不知道哪里有相关的帮助可以查找,谢谢!!
- 前端
- struts2中的prepare问题。
- jsp iframe 引用的问题。
DBconnect修改如下:import java.sql.*;public class DBconnect {
private final String driver = "net.sourceforge.jtds.jdbc.Driver";
private final String url = "jdbc:jtds:sqlserver://localhost:1433/sql";
private final String usename = "ers";
private final String password = "123";
private Connection conn = null;
private Statement stm = null;
private ResultSet res = null; public boolean getConnection() {
try {
Class.forName(driver).newInstance();
} catch (Exception e) {
System.out.println(e.getMessage());
}
boolean resave = false;
try {
conn = DriverManager.getConnection(this.url, this.usename,
this.password);
stm = conn.createStatement();
resave = true;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return resave;
} public boolean update(String sql) {
boolean resave = false;
try {
stm.execute(sql);
resave = true;
sql = null;
} catch (Exception e) {
}
return resave;
} public void query(String sql) {
try {
res = stm.executeQuery(sql);
sql = null;
} catch (Exception e) {
System.out.println(e.getMessage());
}
} public boolean next() {
boolean resave = false;
try {
if (res.next()) {
resave = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return resave;
} public String getValue(String field) {
String value = null;
try {
if (res != null) {
value = res.getString(field);
}
} catch (Exception e) { }
field = null;
return value;
} public void closeRs() {
try {
if (res != null) {
res.close();
}
} catch (Exception e) {
}
} public void closeStm() {
try {
if (stm != null) {
stm.close();
}
} catch (Exception e) {
}
} public void closeConn() {
try {
if (conn != null) {
conn.close();
}
} catch (Exception e) {
}
}
}