I've created a web service to connect my android device to a mysql database. I made the web service in java using eclipse galileo. I know the web service is working well because I can get my method to return a string so, the only possible problem is with my sql query:
我已经创建了一个Web服务来将我的android设备连接到mysql数据库。我使用eclipse galileo在java中创建了web服务。我知道Web服务运行良好,因为我可以让我的方法返回一个字符串,所以唯一可能的问题是我的SQL查询:
public String getUsers()
{
String username = "root";
String password = "ticket";
String tablename = "users";
String fieldname = "*";
String query = "SELECT " + fieldname + " FROM " + "android." + tablename + ";";
/* this chnk of code can appear more or less verbatim */
/* in your database apps (including JSPs) */
String url = "jdbc:mysql://"my IP address":3306/android";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, username, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()){
}
rs.close();
stmt.close();
con.close();
}catch(Exception e){
}
return test;
}
Through debugging: I've narrowed the fail point down to :
通过调试:我将故障点缩小到:
Connection con = DriverManager.getConnection(url, username, password);
But, I can't figure out why I am getting the error.
但是,我无法弄清楚为什么我会收到错误。
I know my "mysql username and password is correct": I got my url from eclipse's database development perspective when I created the connection. Yes, I have tried switching from my IP address to "localhost" and vice versa. It's been a few hours now, and maybe I just need a fresh set of eyes. Any ideas would be much appreaciated.
我知道我的“mysql用户名和密码是正确的”:我在创建连接时从eclipse的数据库开发角度获取了我的url。是的,我尝试从我的IP地址切换到“localhost”,反之亦然。这已经是几个小时了,也许我只需要一双新鲜的眼睛。任何想法都会得到很大的启发。
Thanks.
1 个解决方案
#1
0
If you get a java.lang.ClassNotFoundException
, then you have to be sure that you put your MySQL driver on the class path of your web service implemenation. In Eclipse, this can be done quite easily (I can't tell you how exactly, as I do not know your exact setup). Try googling eclipse classpath
...
如果你得到java.lang.ClassNotFoundException,那么你必须确保将MySQL驱动程序放在Web服务实现的类路径上。在Eclipse中,这可以很容易地完成(我不能告诉你究竟如何,因为我不知道你的确切设置)。尝试谷歌搜索eclipse类路径...
#1
0
If you get a java.lang.ClassNotFoundException
, then you have to be sure that you put your MySQL driver on the class path of your web service implemenation. In Eclipse, this can be done quite easily (I can't tell you how exactly, as I do not know your exact setup). Try googling eclipse classpath
...
如果你得到java.lang.ClassNotFoundException,那么你必须确保将MySQL驱动程序放在Web服务实现的类路径上。在Eclipse中,这可以很容易地完成(我不能告诉你究竟如何,因为我不知道你的确切设置)。尝试谷歌搜索eclipse类路径...