日期:2014-05-17  浏览次数:20981 次

hibernate怎么执行SQL的insert操作(不是HQL哦,是SQL语句)
我的代码是这样的:
Java code

public int insertValue(int pid,String vcode,String vvalue,String state,String mname){
        int flag = 0;
        Session session = null;
        Transaction tr = null;
        try{
            if(pid>0&&vcode!=null&&vvalue!=null&&mname!=null){
                session = getSession();
                String sql = "insert into sf_3_clinic(pid,"+vcode+") values("+pid+","+vvalue+")"; 
                System.out.println(sql);
                tr=session.beginTransaction();
                //Statement state1 = session.connection().createStatement();
                session.createSQLQuery(sql);
                tr.commit(); 
                session.close();
            }
        }catch(Exception e){
            e.printStackTrace();return 0;
        }
        return 0;
    }



没有报错,但是数据库中没有数据~!求指点,谢谢啦

------解决方案--------------------
问题解决了就好。
------解决方案--------------------
探讨

Java code

public int insertValue(int pid,String vcode,String vvalue,String state,String mname){
Session session = null;
Transaction tr = null;
Connection con = null;
……

------解决方案--------------------
探讨

Java code

public int insertValue(int pid,String vcode,String vvalue,String state,String mname){
Session session = null;
Transaction tr = null;
Connection con = null;
……