Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 另一个CallableStatement的问题
Jsharp





发贴: 30
积分: 0
于 2006-08-03 02:18 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
数据库:sqlserver2000
操作系统 winxp 2
存储过程如下
CREATE proc adduser
@name varchar(20),@pwd varchar(20)
as
insert into users values(@name,@pwd)
程式代码如下
public void reg() {
System.out.println("请输入你的用户名:");
String username = input();//input()方法返回一个控制台输入的字符串
System.out.println("请输入你的密码:");
String passwd = input();
System.out.println("请再次输入你的密码:");
String passwd2 = input();
String id1 = String.valueOf((int) (Math.random() * 10));
String id2 = String.valueOf((int) (Math.random() * 10));
String id3 = String.valueOf((int) (Math.random() * 10));
String id4 = String.valueOf((int) (Math.random() * 10));
String id = id1 + id2 + id3 + id4;
System.out.println("请输入你看到的右边的验证码:" + id);
String idd = input();
regCheck(username, passwd, passwd2, idd, id);
}
public void regCheck(String username, String passwd, String passwd2,
String idd, String id) {
if (passwd.compareTo(passwd2) != 0) {
System.out.println("两次输入密码不同");
reg();
} else if (passwd.compareTo(passwd2) == 0 && idd.compareTo(id) == 0) {

ConnectBean conBean = new ConnectBean();
Connection conn = conBean.getConnection();
if (conn == null) {
System.out.println("连接数据库失败");
}
try {
cst = conn.prepareCall("{call adduser(?,?)}");
cst.setString(1, username);
cst.setString(2, passwd);
cst.executeUpdate();
System.out.println("注册成功!");
login();
} catch (SQLException ex) {
} finally {
try {
cst.close();
} catch (SQLException ex1) {
}
}

} else if (idd.compareTo(id) != 0) {
System.out.println("验证码输入错误");
reg();
}
}
这样之后数据库中的确加入了一个username 和passwd
提出passwd数据后和在控制台输入的密码数据无论用equals或compareTo方法比较结果都是false但如果直接在数据库中添加数据则能判断为true或直接在数据库中调用存储过程做判断结果都是true实在搞不明白 请帮帮我 谢谢大家




话题树型展开
人气 标题 作者 字数 发贴时间
17205 另一个CallableStatement的问题 Jsharp 2180 2006-08-03 02:18
13899 Re:另一个CallableStatement的问题 why 37 2006-08-03 08:57
14156 Re:另一个CallableStatement的问题 Jsharp 752 2006-08-03 14:36
13959 Re:另一个CallableStatement的问题 Jsharp 3093 2006-08-03 15:29
13859 Re:另一个CallableStatement的问题 why 167 2006-08-03 15:33
14083 Re:另一个CallableStatement的问题 Jsharp 40 2006-08-03 15:41
15268 Re:另一个CallableStatement的问题 Jsharp 110 2006-08-03 16:22

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923