问题一:无法连接云端服务器数据库
DBUtils代码:
package com.example.echo.myapplication;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
public class DBUtils {
private static final String TAG = "DBUtils";
private static String ip="172.17.212.194";
private static String user="root";
private static String pwr="";
//private static String url="jdbc:mysql://172.x.x.x:3306/jujia&autoReconnect=true&failOverReadOnly=false";
private static String url="jdbc:mysql://172.x.x.x:3306/jujia&autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private static Connection getConnection() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver"); //加载驱动
Log.i("helen","driver check");
String ip = "x.x.x.x";
Log.i("helen","start");
// conn = DriverManager.getConnection(
// "jdbc:mysql://" + ip + ":3306/" + dbName,
// "learner", "learner_password");
conn=DriverManager.getConnection(url,user,pwr);
Log.i("helen","success");
} catch (SQLException ex) {
Log.i("helen","failed");
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return conn;
}
public static HashMap<String, String> getUserInfoByName(String name) {
HashMap<String, String> map = new HashMap<>();
Log.i("helen","getcon before check");
Connection conn = getConnection();
Log.i("helen","getcon after check");
try {
Statement st = conn.createStatement();
String sql = "select * from user where name = '" + name + "'";
ResultSet res = st.executeQuery(sql);
if (res == null) {
return null;
} else {
int cnt = res.getMetaData().getColumnCount();
//res.last(); int rowCnt = res.getRow(); res.first();
res.next(