参考:
http://blog.csdn.net/cxwen78/article/details/6863696
Demo:
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://10.9.17.250:3306/ps3", userName,
userPassword);
Statement statment = conn.createStatement();
ResultSet resultSet = statment.executeQuery("select * from user");
while (resultSet.next()) {
System.out.println(resultSet.getInt("user_id") + " "
+ resultSet.getString("user_name"));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
conn.close();
}
}