易截截图软件、单文件、免安装、纯绿色、仅160KB

自学者的求助:JSP连接数据库的问题。。

Java code:

<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%!
private void delete(Connection conn,int id){
Statement stmt=null;
try{
stmt=conn.createStatement();
String sql="delete from article where pid="+id;
stmt.executeUpdate(sql);
stmt.executeUpdate("delete from article where id="+id);}catch(SQLException e){
e.printStackTrace();
}finally{
if(stmt!=null){
stmt.close();
stmt=null;
}
}

}
%>
<%
int id=Integer.parseInt(request.getParameter("id"));
int pid=Integer.parseInt(request.getParameter("pid"));
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;Databasename=bbs;SelectMethod=Cursor","sa","sa");

conn.setAutoCommit(false);

delete(conn,id);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from article where pid="+pid);
rs.next();
int count=rs.getInt(1);
if(count<=0){
stmt.executeUpdate("update article set isleaf=0 wh


相关问答:

JSP存入数据库

我是用STRUTS ,做了一个JSP页面,提交后没有存入数据库。
JSP代码如下:
aa.jsp代码
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ taglib uri=" ......

Unable to compile class for JSP - Java / Web 开发

<%@page language="java" contentType="text/html;charset=gb2312" import="java.sql.*"%>
<jsp:useBean id="db" class="wang.connectDB"/>
< ......

JSP 接收 FORM 提交 - Java / Web 开发

一个JSP页面接收其他页面提交过来的FORM表单,但是要求只接收当前站点及其子站点提交过来的FORM表单,其他站点提交过来的表单不接收,这个怎么设置?
用过滤器
filter
将当前站点及其子站点放一个目录 
然 ......

jsp页面如何保存成html格式 - Java / Web 开发

我在jsp页面查询到数据库中的一笔数据,并以table循环的形式显示,但需要下载保存成html格式,请问应该处理?代码有没有特殊要求?是不是需要特别的jar包?
你这是把报表保存为HTML格式,不知有什么用处,
要是 ......

tomcat环境下jsp编译错误,求解! - Java / Web 开发

org.apache.jasper.JasperException: Unable to compile class for JSP: 
An error occurred at line: 52 in the jsp file: /vip_info.jsp
ÕË cannot be resolved
49: <table border="1& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号