下記のコードにてMYSQLへ接続し、URL「http://hogehoge/hoge/api/hoge/search?hoge=*」で指定した範囲の結果表示をしたいです。
しかし、例外やエラーが続出していまい、作業がとまっています。
いろいろ調べたりしているのですがよくわかりません。
@GET
@Path("search?hoge={hoge}")
public ArrayList<Hogehoge> getHoge(@QueryParam("hoge") Integer hoge){
ArrayList<Hogehoge> list = new ArrayList<Hogehoge>();
Hogehoge hoge;
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+"";
ResultSet rs = 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 (Exception e) {
System.out.println("例外発生:" + e);
}
return null;
}
下記のClassで実行?されます
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<>();
resources.add(Hogehoge.class);
return resources;
}
}
下記エラー、例外です。長くてすみません。
警告: 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;q=0.9,*/*;q=0.8,. Please enable FINE/TRACE log level for more details. [金 1 23 14:14:35 JST 2015]
警告: javax.ws.rs.WebApplicationException
at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:415)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:216)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.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.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
" and hoge.hoge = "+hoge+""
を" and hoge.hoge = '"+hoge+"'"
に直すべきかなとは思いますが、例外スタックトレースがあればちゃんと原因がわかりそうな気がします。getHoge()
が定義されているclassを含むコードを質問文に記載すると良さそうです。私は少しPCから離れる為、即答出来ませんが。。。