【问题标题】:java- javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException:could not execute statementjava-javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法执行语句
【发布时间】:2019-03-20 08:59:43
【问题描述】:

我正在尝试按如下方式执行我的 SQL 语句:

public String get_value(long nodeid,String ts) {
        try {
            String sql="Select URL FROM urllink WHERE URL="+nodeid;
            em.createNativeQuery(sql).executeUpdate();
            if (em == null) {
                throw new Exception("could not found URL object.");
            }
          //  return 1;

        } catch (Exception e) {
            e.printStackTrace();



        }
       return null;
    }

它会抛出异常消息:

javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException:could not execute statement

当我调用 executeUpdate() 时。

我是不是做错了什么?

编辑: 我正在尝试以这种格式传递 URL 参数:

http://126.32.3.11:8080/repository/file/view/viewPDF.jsp?f0=27491&ts=2019.03.20.16.50.58

并使用这些参数检查它们是否存在于列中,如果存在,则运行我的viewPDF.jsp

 public String get_value(long nodeid,String ts) {
        try {
            String sql="Select URL FROM urllink WHERE URL="+"'f0='"+nodeid+"'&ts='"+ts;
            em.createNativeQuery(sql).executeUpdate();
            if (em == null) {
                throw new Exception("could not found URL object.");
            }
          //  return 1;

        } catch (Exception e) {
            e.printStackTrace();



        }
       return null;
    }

【问题讨论】:

    标签: java hibernate persistence


    【解决方案1】:

    executeUpdate() 用于更新和删除查询。

    对于选择查询,使用getResultList()getSingleResult() 检索结果

    Query q = em.createNativeQuery(sql);
    List<Object[]> result= q.getResultList();
    

    【讨论】:

    • 我基本上是在尝试检查我的列中是否存在确切的记录,如果是,则执行页面 JSP。
    • 阅读答案并尝试理解它在说什么
    • 我仍然得到 SQLGrammarException
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    • 2013-06-28
    • 2016-03-28
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多