首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

初学者问个SQL语句 insert 有关问题

2012-11-04 
菜鸟问个SQL语句 insert 问题String sqlinsert into course(cou_id , cou_name , xuefen , collo_id,dep

菜鸟问个SQL语句 insert 问题
String sql="insert into course(cou_id , cou_name , xuefen , collo_id,dept_id)  
select '"+new String(cou_id.getBytes(),"GBK")+"' , '"+new String(cou_name.getBytes(),"GBK")+"' , '"+new String(xuefen.getBytes(),"GBK")+"' , (select collo_id from dept where dept_name='"+new String(dept_name.getBytes(),"GBK")+"' ) , (select dept_id from dept where dept_name='"+new String(dept_name.getBytes(),"GBK")+"'))";
我连接的是sql server 2005 cou_id , cou_name , xuefen 都是自己填写的 collo_id,dept_id是根据下拉菜单选项得出的
这句话有问题吗? 一执行int i=stmt.executeUpdate(sql); 就会发生异常 求指点

[解决办法]
catch(Exception ea){//该编号课程已经存在
JOptionPane.showMessageDialog(this,"添加失败!!!,该编号的课程已经存在",
"错误",JOptionPane.ERROR_MESSAGE);
}

为啥不把异常信息打印出来,非得”自作聪明“的写什么"添加失败“

ea.printStackTrace();

热点排行
Bad Request.