需要的jar 下载
private static final String url = "jdbc:mysql://192.168.xx.xxx:3306/yy"; //数据库地址
private static final String username = "root"; //数据库用户名
private static final String password = ""; //数据库密码
private static final String driver = "com.mysql.jdbc.Driver"; //mysql驱动
private static final Connection conn = null;
public static void main(String[] args) {
Connection conn = conn(); //连接数据库
PreparedStatement stmt;
String sql = "select * from xx";
List<Map> list =new ArrayList<Map>();
try {
stmt= conn.prepareStatement(sql);
ResultSet executeQuery = stmt.executeQuery();
String s = null;
while(executeQuery.next()){
s=executeQuery.getString("content");
}
//String(json字符串转list<map>)
list = JSONObject.parseArray(s, Map.class);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection conn() {
Connection conn = null;
try {
Class.forName(driver); //加载数据库驱动
try {
conn = DriverManager.getConnection(url, username, password); //连接数据库
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
}