高手们 帮忙啊!

snoopy123808 2006-08-13 02:37:39
编写了一个测试数据库的代码如下:
addUser.html
<html>
<head><title>user add</title></head>
<body>
<form method="post" action="jdbc.jsp">
<p align="center">姓名:
<input type="text" name="name" size="20"> </p>
<p align="center">密码:
<input type="password" name="pwd" size="20">
</p>
<p align="center">
<input type="submit" value="提交" name="B1"></p>
</form>
</body>
</html>
jdbc.jsp
<html>
<head><title>add user to DB</title></head>
<%@page import="java.sql.*"%>
<body>
<pre>
<%
String name,pwd;
name=request.getParameter("name");
pwd=request.getParameter("pwd");
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:jspTest");
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into tbUser values('"+name+"','"+pwd+"')" );
ResultSet rs=stmt.executeQuery("select * from tbUser");
out.println("all user from db");
while(rs.next())
{
out.print("user name:");
out.print(rs.getString("name")+" password:");
out.print(rs.getString("password"));
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.print(e.getMessage());
}
%>
</pre>
</body>
</html>
当输入姓名 密码 提交后出现下列问题
[Microsoft][ODBC SQL Server Driver][SQL Server]?? '(null)' ???????: ???? SQL Server ??????
请问怎样改
...全文
138 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
snoopy123808 2006-08-14
  • 打赏
  • 举报
回复
可以了,好像就是没加登录名和密码
jonye 2006-08-14
  • 打赏
  • 举报
回复
数据库的设计有问题吧?
snoopy123808 2006-08-13
  • 打赏
  • 举报
回复
对阿,我只是对数据库做个测试,所以没加太多的字段
Anser 2006-08-13
  • 打赏
  • 举报
回复
行不行的怎么也不回呀!
Anser 2006-08-13
  • 打赏
  • 举报
回复
Connection con=DriverManager.getConnection("jdbc:odbc:jspTest");应该写成:
Connection con=DriverManager.getConnection("jdbc:odbc:jspTest","登陆名","密码");
kevinliuu 2006-08-13
  • 打赏
  • 举报
回复
你的tbUser表只有两个字段吗
lina511 2006-08-13
  • 打赏
  • 举报
回复
没错
snoopy123808 2006-08-13
  • 打赏
  • 举报
回复
是不是我这条查询语句错了: stmt.executeUpdate("insert into tbUser values('"+name+"','"+pwd+"')" );
snoopy123808 2006-08-13
  • 打赏
  • 举报
回复
我刚才看了一下我的表就俩个字段阿
huihui0103 2006-08-13
  • 打赏
  • 举报
回复
空指针也不报这个呀,大哥。。。
我觉得还是sql语句的问题。。。要不你捕获一下吧
try catch
eoe2005 2006-08-13
  • 打赏
  • 举报
回复
错了
是孔子征异常
插入前并没有的到name和pws得知
eoe2005 2006-08-13
  • 打赏
  • 举报
回复
你的表有三个字段,但是你插入的时候只插入了2个字段
所以抱错

81,092

社区成员

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

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