【发布时间】:2015-03-23 22:35:02
【问题描述】:
我正在尝试使用端点在 Eclipse 中使用 tomcat 7 作为服务器来质疑 mysql 数据库,但它总是给我这个错误,有人用 jdbi 解决了这个问题
输入异常报告
消息 java.sql.SQLException: 找不到合适的驱动程序 jdbc:mysql://127.0.0.1/demo
The code:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.json.JSONObject;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
@Path("/jdbiservice")
public class JdbiService {
@Path("{f}")
@GET
@Produces("application/json")
public Response convertFtoCfromInput(@PathParam("f") int f) throws JSONException {
DBI dbi = new DBI("jdbc:mysql://127.0.0.1/demo", "user", "pass");
Handle h = dbi.open();
BatchExample b = h.attach(BatchExample.class);
Something s =b.findById(f);
h.close();
JSONObject jsonObject = new JSONObject(s);
String result = jsonObject.toString();
return Response.status(200).entity(result).build();
}
}
您好,在 Eclipse 项目路径和 tomcat lib 文件夹内有 jar 连接器文件。
【问题讨论】: