1
public String passlink(String companyName, String mailName) {

    Session session = Hibernateutil.getSessionFactory().openSession();

    Transaction transaction = null;

    try {
        transaction = session.beginTransaction();

        String queryString="UPDATE account SET companyname = :companyName WHERE companyname like 'm' AND Email LIKE :mailName";
        Query query=session.createQuery(queryString);

        query.setParameter("companyName", companyName);
        query.setParameter("mailName", mailName);
        int result = query.executeUpdate();

        System.out.println("Rows affected: " + result);

            System.out.println("Successfully updated");
        transaction.commit();

    } catch (Exception e) {
        value = "FAIL";
                   e.printStackTrace();
        //System.out.println("Error--> " + e.getMessage());
    }
    return value;

}

更新クエリを作成します

String queryString = "UPDATE account SET companyname =:companyName WHERE companyname like'm' AND Email LIKE:mailName";

このようになりますが、次のエラーが発生します。

java.lang.IndexOutOfBoundsException:インデックス:0、サイズ:0 at java.util.ArrayList.RangeCheck(Unknown Source)at java.util.ArrayList.get(Unknown Source)at org.hibernate.hql.ast.HqlSqlWalker.postProcessUpdate( HqlSqlWalker.java:390)at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:164)at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)at org.hibernate.hq .ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425)at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:861)のorg.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:880)impl.QueryImpl.executeUpdate(QueryImpl.java:89)at com.njob.dao.AccountDao.passlink(AccountDao.java:213)at com.njob.action.companylink.doPost(companylink.java:34)at javax.servlet .http.HttpServlet.service(HttpServlet.java:709)at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)at org.apache.catalina.core.StandardContextValve.invoke( StandardContextValve.java:178)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)atorg.apache.catalina.valves.ErrorReportValve。invoke(ErrorReportValve.java:105)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)at org.apache .coyote.http11.Http11Processor.process(Http11Processor.java:825)at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.processConnection(Http11Protocol.java:731)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket (PoolTcpEndpoint.java:526)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)at org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:684 )java.lang.Thread.run(不明なソース)107)org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.processConnection(Http11Protocol.java:731)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java :80)org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:684)at java.lang.Thread.run(Unknown Source)107)org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.processConnection(Http11Protocol.java:731)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java :80)org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:684)at java.lang.Thread.run(Unknown Source)Http11Protocol $ Http11ConnectionHandler.processConnection(Http11Protocol.java:731)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorker java:80)at org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:684)at java.lang.Thread.run(Unknown Source)Http11Protocol $ Http11ConnectionHandler.processConnection(Http11Protocol.java:731)at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorker java:80)at org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:684)at java.lang.Thread.run(Unknown Source)

4

2 に答える 2

3

クエリを次のように変更します

String queryString="UPDATE account SET companyname = :companyName WHERE companyname like 'm' AND email LIKE :mailName";

そして使う

query.setParameter("companyName", companyName);
query.setParameter("mailName", mailName);

見る

于 2012-08-08T07:50:55.390 に答える
1

これを試して

 query.setParameter("companyName", companyName);

使用するパラメータは companyName です

于 2012-08-08T07:44:17.697 に答える