Error when connecting to Mysql and executing query in Java web app

Asked 1 years ago, Updated 1 years ago, 84 views

I would like to connect to MYSQL using the code below and display the results of the range specified in the URL http://hogehoge/hoge/hoge/search?hoge=*".
However, there have been many exceptions and errors, and the work has stopped.
I've been doing a lot of research, but I'm not sure.

@GET
@Path("search?hoge={hoge}")
publicArrayList<Hogehoge>getHoge(@QueryParam("hoge") Integerhoge){

    ArrayList<Hogehoge>list=new ArrayList<Hogehoge>();
    Hogehoge hogehoge;

    hoge = new Hogehoge();
    try{
        Class.forName("com.mysql.jdbc.Driver");

        String url = "jdbc:mysql://localhost/SampleDB040";
        String user = "testmysql";
        String password = "******";

        Connection conn = DriverManager.getConnection(url, user, password);
        System.out.println(conn.getMetaData().getDatabaseProductName());

        Statement stmt = conn.createStatement();
        String sql = "select hoge, hoge, hoge, hoge, hoge"
                + "from hoge, hoge, hoge, hoge"
                + "where hoge.hoge=hoge.hoge"
                + "and hoge.hoge=hoge.hoge"
                + "and hoge.hoge=hoge.hoge"
                + "and order by hoge"
                + " and hoge.hoge="+hoge+"";

        ResultSetters=stmt.executeQuery(sql);

        System.out.println();

        while(rs.next()){


            hoge = new Hogehoge();

            pref.setHogeCd(rs.getInt("hoge")); 
            pref.setHoge1Name(rs.getString("hoge")); 
            pref.setHoge2Name(rs.getString("hoge")); 
            pref.setHoge3Name(rs.getString("hoge")); 
            pref.setHoge4Name(rs.getString("hoge")); 

            list.add(hoge);

        }

    } catch(Exceptione){
        System.out.println("Exception occurred:"+e);
    }
    return null;
}

Run with the class below?Yes

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ ApplicationPath("/api")
public class ApplicationConfig extensions Application {

    @ Override
    publicSet<Class<?>>GetClasses(){
        Set<Class<?>>resources=new HashSet<>();

        resources.add(Hogehoge.class);

        return resources;
    }

}

The following error is an exception.Sorry for the long time.

Warning: No operation matching request path"/rest-sample/api/pref/1" is found, Relative Path: /1, HTTP Method: GET, ContentType: */*, Accept: text/html, application/xhtml+xml, image/webp, application/xml;qeml;qE;=0.0, PLE=0.8
Warning: javax.ws.rs.WebApplicationException
atorg.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod (JAXRSUtils.java:415)
at org.apache.cxf.jaxrs.interceptor.JAXRSInterceptor.processRequest (JAXRSInInterceptor.java:216)
at org.apache.cxf.jaxrs.interceptor.JAXRSInterceptor.handleMessage (JAXRSInInterceptor.java:91)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept (PhaseInterceptorChain.java:263)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage (ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke (AbstractHTTPDestination.java:240)
at org.apache.openejb.server.cxf.rs.CxfRsHttpListener.onMessage (CxfRsHttpListener.java:187)
at org.apache.openejb.server.rest.RsServlet.service(RsServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:122)
at org.apache.tomee.catalina.OpenEJBValve.invoke (OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process (AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run (JIoEndpoint.java:316)
at java.util.current.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
at java.util.current.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunable.run(TaskThread.java:61)
at java.lang.Thread.run (Thread.java:745)

java mysql jax-rs

2022-09-30 19:24

1 Answers

Modifying @Path("search?hoge={hoge}") to @Path("{hoge}")
I changed the return null; to List and it worked fine.

The result this time was due to my lack of code confirmation.
Sorry for the trouble.


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.