当前位置: 代码迷 >> Java相关 >> [求助]数据库连接错误
  详细解决方案

[求助]数据库连接错误

热度:194   发布时间:2007-01-14 13:07:10.0
看看有没有异常啊
----------------解决方案--------------------------------------------------------
没有啊
----------------解决方案--------------------------------------------------------
你把数据库的代码全部拷贝上来.
----------------解决方案--------------------------------------------------------

create table kh(
kid char(4) not null primary key,
kname char(20) ,
ksex char(2) default '男' check (ksex='男' or ksex='女'),
kage smallint,
ktime smalldatetime);

create table room(
rid char(4) not null primary key,
rtype smallint,
rrn smallint);

create table kr(
kid char(4) not null foreign key references kh(kid),
rid char(4) not null foreign key references room(rid),
rd smallint,
rmoney int,
primary key(kid,rid),
);

insert into kh values('0001','周楠','男',20,'2007-05-08 12:35');
insert into kh values('0002','钱勇勇','男',20,'2007-05-08 12:35');
insert into kh values('0003','陆向荣','男',20,'2007-05-08 12:35');
insert into kh values('0004','周明','男',20,'2007-05-08 12:35');
insert into kh values('0005','冯树彪','男',20,'2007-05-08 12:35');
insert into kh values('0006','胥睿','男',20,'2007-05-08 12:35');

insert into room values('0001'1,2);
insert into room values('0002'2,2);
insert into room values('0003'3,2);
insert into room values('0004'4,2);
insert into room values('0005'5,2);
insert into room values('0006'6,2);

insert into kr values('0001','0001',1,null);
insert into kr values('0002','0002',2,null);
insert into kr values('0003','0003',1,null);
insert into kr values('0004','0004',1,null);
insert into kr values('0005','0006',1,null);
insert into kr values('0006','0005',1,null);


----------------解决方案--------------------------------------------------------
以下是引用tigershi10在2007-1-14 11:59:27的发言:
我感觉好象是比较那边错了
if (rs.next()){

//text.append("\t"+"\t"+rs.getString("room_num")+"\n");
if(rs.getString("kid").trim().equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"此房间已经满了");}

else
JOptionPane.showMessageDialog(null,"此房间空着");
}

你从数据库取来的的字符串,可能尾部加了很多空格


----------------解决方案--------------------------------------------------------
if (rs.next()){

//text.append("\t"+"\t"+rs.getString("room_num")+"\n");
if(rs.getString("kid").equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"此房间已经满了");}

else
JOptionPane.showMessageDialog(null,"此房间空着");
}
改成
if (rs.next()){

//text.append("\t"+"\t"+rs.getString("room_num")+"\n");
if(rs.getString("kid").equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"此房间已经满了");}
}
else
JOptionPane.showMessageDialog(null,"此房间空着");
看看
----------------解决方案--------------------------------------------------------
以下是引用tigershi10在2007-1-14 13:14:10的发言:

create table kh(
kid char(4) not null primary key,
kname char(20) ,
ksex char(2) default '男' check (ksex='男' or ksex='女'),
kage smallint,
ktime smalldatetime);

create table room(
rid char(4) not null primary key,
rtype smallint,
rrn smallint);

create table kr(
kid char(4) not null foreign key references kh(kid),
rid char(4) not null foreign key references room(rid),
rd smallint,
rmoney int,
primary key(kid,rid),
);

insert into kh values('0001','周楠','男',20,'2007-05-08 12:35');
insert into kh values('0002','钱勇勇','男',20,'2007-05-08 12:35');
insert into kh values('0003','陆向荣','男',20,'2007-05-08 12:35');
insert into kh values('0004','周明','男',20,'2007-05-08 12:35');
insert into kh values('0005','冯树彪','男',20,'2007-05-08 12:35');
insert into kh values('0006','胥睿','男',20,'2007-05-08 12:35');

insert into room values('0001'1,2);
insert into room values('0002'2,2);
insert into room values('0003'3,2);
insert into room values('0004'4,2);
insert into room values('0005'5,2);
insert into room values('0006'6,2);

insert into kr values('0001','0001',1,null);
insert into kr values('0002','0002',2,null);
insert into kr values('0003','0003',1,null);
insert into kr values('0004','0004',1,null);
insert into kr values('0005','0006',1,null);
insert into kr values('0006','0005',1,null);

别把这个贴出来了
insert into room values('0001'1,2);
insert into room values('0002'2,2);
insert into room values('0003'3,2);
insert into room values('0004'4,2);
insert into room values('0005'5,2);
insert into room values('0006'6,2);
这是啥呀
----------------解决方案--------------------------------------------------------
上面的数据库里面分别加一个逗号.
----------------解决方案--------------------------------------------------------

我试试看


----------------解决方案--------------------------------------------------------
以下是引用中文名在2007-1-14 13:15:46的发言:
if (rs.next()){

//text.append("\t"+"\t"+rs.getString("room_num")+"\n");
if(rs.getString("kid").equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"此房间已经满了");}

else
JOptionPane.showMessageDialog(null,"此房间空着");
}
改成
if (rs.next()){

//text.append("\t"+"\t"+rs.getString("room_num")+"\n");
if(rs.getString("kid").equals(jt.getText().trim())){
JOptionPane.showMessageDialog(null,"此房间已经满了");}
}
else
JOptionPane.showMessageDialog(null,"此房间空着");
看看

你上面哪儿改了哦
还有封哥,按你改了之后,还不行哦
----------------解决方案--------------------------------------------------------

  相关解决方案