在线等小问题请帮忙谢谢

wuxinlangman 2005-04-27 11:54:47
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
</html>
<head>
<title>添加评论</title>
</head>
<body>
<%@ include file="include.inc"%>
<%
try
{
Class.forName(CLASSFORNAME);
Connection con=DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement stmt=con.createStatement();
String ip=request.getRemoteAddr();
java.util.Date time=new java.util.Date();
String sqltime=new Timestamp(time.getTime()).toString();
String xwxh=request.getParameter("xwxh");
String plr=request.getParameter("author");
String plnr=request.getParameter("plnr");
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values(´"+xwxh+"´,´"+plr+"´,´"+sqltime+"´,´"+ip+"´,´"+plnr+"´)");
stmt.close();
con.close();
out.println("添加成功");
out.print("系统会自动专向评论页面;如果没有成功请点击");
out.print("<a href=news_show.jsp?xwxh=3>返回</a>");
out.print("<meta http-equiv=refresh content=´4;url=news_show.jsp?xwxh=3´>");

}
catch(Exception e)
{
e.printStackTrace();
}
%>
<center>
</body>
</html>
include.inc:
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="com.microsoft.jdbc.sqlserver.SQLServerDriver"%>
<%@ page import="java.lang.*"%>
<%
String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String SERVANDDB="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=wuxin";
String USER="sa";
String PWD="wuxin";
%>
为什么不能执行数据库
还有不能显示out.print();所要输出的东西
...全文
137 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxinlangman 2005-04-28
  • 打赏
  • 举报
回复
为什么是int的就不要外面的引号呢
xtaotao 2005-04-28
  • 打赏
  • 举报
回复
语句是这样的话:
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values('"+xwxh+"','"+plr+"','"+sqltime+"','"+ip+"','"+plnr+"')");
你的xwxh字段是int的话,应该语句这样写吧:

stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values("+xwxh+",'"+plr+"','"+sqltime+"','"+ip+"','"+plnr+"')");
---------

即去掉 xwxh 外面的单引号.
fengyue2001 2005-04-28
  • 打赏
  • 举报
回复
你的sql字段设定有没有错误,建议到sql中验证一下sql语句是否正确
wuxinlangman 2005-04-28
  • 打赏
  • 举报
回复
没有人在了吗?帮帮忙阿
xtaotao 2005-04-28
  • 打赏
  • 举报
回复
加了引号就是字符串类型了
ailingfor 2005-04-27
  • 打赏
  • 举报
回复
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values(´"+xwxh+"´,´"+plr+"´,´"+sqltime+"´,´"+ip+"´,´"+plnr+"´)"); 这句有错吧
改为这样:
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values(´'"+xwxh+"'´,´'"+plr+"'´,´'"+sqltime+"'´,´'"+ip+"'´,´'"+plnr+"'´)");
试试
MARS.nEIL 2005-04-27
  • 打赏
  • 举报
回复
没出现什么错误吗??
MARS.nEIL 2005-04-27
  • 打赏
  • 举报
回复
看错了..
MARS.nEIL 2005-04-27
  • 打赏
  • 举报
回复
Class.forName(CLASSFORNAME);
Connection con=DriverManager.getConnection(SERVANDDB,USER,PWD);
常量没有定义..
wuxinlangman 2005-04-27
  • 打赏
  • 举报
回复
没有异常什么都没有
就是一个空白网页
但是我把
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values('"+xwxh+"','"+plr+"','"+sqltime+"','"+ip+"','"+plnr+"')");
这句以注销掉就可以显示out.print("");
其中有个字段xwxh在数据库中是int类型的
s3x4 2005-04-27
  • 打赏
  • 举报
回复
应该有异常吧
EchoEverything 2005-04-27
  • 打赏
  • 举报
回复
请问,没有异常抛出吗?
wuxinlangman 2005-04-27
  • 打赏
  • 举报
回复
不是是SQLServer数据库

s3x4 2005-04-27
  • 打赏
  • 举报
回复
如果是ORACLE的话,这样写SQL语句是每问题的,看看有什么错误信息吧
wuxinlangman 2005-04-27
  • 打赏
  • 举报
回复
按照你说的还是不行啊
wuxinlangman 2005-04-27
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
</html>
<head>
<title>添加评论</title>
</head>
<body>
<%@ include file="include.inc"%>
<%
try
{
Class.forName(CLASSFORNAME);
Connection con=DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement stmt=con.createStatement();
String ip=request.getRemoteAddr();
java.util.Date time=new java.util.Date();
String sqltime=new Timestamp(time.getTime()).toString();
String xwxh=request.getParameter("xwxh");
String plr=request.getParameter("author");
String plnr=request.getParameter("plnr");
stmt.execute("insert into yzcy_newscomment(xwxh,plr,plsj,ip,plnr)values('"+xwxh+"','"+plr+"','"+sqltime+"','"+ip+"','"+plnr+"')");
stmt.close();
con.close();
out.println("添加成功");
out.print("系统会自动专向评论页面;如果没有成功请点击");
out.print("<a href=news_show.jsp?xwxh=3>返回</a>");
out.print("<meta http-equiv=refresh content='4;url=news_show.jsp?xwxh=3'>");

}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>

不好意思那个是我复制的时候有点错误

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧