DriverManager.getconnection()参数问题

[复制链接]
查看11 | 回复0 | 2021-1-27 06:48:00 | 显示全部楼层 |阅读模式
最近在用AndroidStudio连接云端服务器上的数据库。使用的是xampp,里面用的是mysql5.5
通过查看logcat发现是DriverManager.getconnection这句话的问题,但是不知道错在哪里
url里的ip地址是我在服务器里的cmd通过ipconfig得到的IPv4参数,这里我删掉了
用户名和密码也没有错,但就是不知道哪里有错
程序运行时不报错但是会显示:



下面是连接数据库的代码以及logcat,使用的是AndroidStudio
publicclassDBUtils{
privatestaticfinalStringTAG="DBUtils";
privatestaticStringurl="jdbc:mysql://172...:3306/jujia";
privatestaticStringuser="root";
privatestaticStringpwr="970819";
privatestaticConnectiongetConnection(){
Connectionconn=null;
Log.i("wzx","test1");
try{
Class.forName("com.mysql.jdbc.Driver");
Log.i("wzx","test2");
}catch(ClassNotFoundExceptione1){
Log.i("wzx","加载驱动失败");
e1.printStackTrace();
}
Log.i("wzx","classfornae");
try{
Log.i("wax","test3");
conn=DriverManager.getConnection(url,user,pwr);
Log.i("wzx","conntest");
}catch(SQLExceptione){
Log.i("wzx","failed");
}
Log.i("wzx","success");
returnconn;
}
publicstaticHashMapgetUserInfoByName(Stringname){
HashMapmap=newHashMap();
Log.i("wzx","beforeGetconnectiontest");
Connectionconn=getConnection();
try{
Statementst=conn.createStatement();
Stringsql="select*frommanagerwhereMID='"+name+"'";
ResultSetres=st.executeQuery(sql);
if(res==null){
returnnull;
}else{
intcnt=res.getMetaData().getColumnCount();
//res.last();introwCnt=res.getRow();res.first();
res.next();
for(inti=1;i -->
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行