【发布时间】:2014-07-07 21:19:38
【问题描述】:
伙计们,我正在尝试使用 RESTful 和 MySQL 在 Java 中开发一个简单的身份验证应用程序。
对于服务器,我使用以下代码
import java.sql.Connection;
import java.sql.DriverManager;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
// http://localhost:8080/2.ServerUserAPI/rest/User?Username=david
@Path("/User")
public class Main{
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello(@QueryParam("Username") String Username) throws Exception{
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/CloudDB", "root", "eusgr1");
PreparedStatement statement = con.prepareStatement("SELECT Username FROM UserAuthentication");
}
catch (Exception e){
throw e;
}
return "qwer";
}
}
但我收到以下错误:找不到适合 jdbc:mysql://localhost/CloudDB 的驱动程序
我已经包含了mysql的jar文件 我还包括了球衣的罐子。
当我通过为以下对象放置 cmets 来尝试此操作时:
//Connection con = DriverManager.getConnection("jdbc:mysql://localhost/CloudDB", "root", "eusgr1");
它在服务器上运行良好。此外,当在不同的班级中使用public static void main{ ... connection ...} 建立连接时
它再次起作用。
如何将这两者(RESTful 和 MySQL)结合起来??
感谢您的帮助。
【问题讨论】:
-
我发布的内容有一个细节,它不仅适用于 MySQL 连接...... !!!正如我在上面所写的,我尝试通过 RESTful Web 服务连接 MySQL。我还写过我能够在一个简单的应用程序中将 Java 与 MySQL 连接起来。我遇到了 RESTful 的这个问题!
标签: java mysql rest restful-authentication