从javaweb项目学习

1.sql语句

在insert语句中需要插入查询出来的值。 Insert into a (a1,a2,a3) values (1,select num from b where id=1,3) 这样写就出现了“在此上下文中不允许使用子查询。只允许使用标量表达式。”这个错误

可以这样: insert into a (a1,a2,a3) select 1,num,3 from b where id=1 即可解决问题.

 

2.如何将string类型转化为sql.date(util.date与sql.date不能直接转化)

        if (year != null && month != null && day != null) {            
            String birthday = year + "-" + month + "-" + day;
            SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");  
            java.util.Date d = null;  
            try {  
                d = format.parse(birthday);  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
            java.sql.Date date = new java.sql.Date(d.getTime());
            user.setuBirthday(date);

 

3.除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。

 

posted @ 2017-05-27 04:50  一只努力向上的猪  阅读(217)  评论(0编辑  收藏  举报