1. 程式人生 > >mysql 數據庫連接

mysql 數據庫連接

user 數據 res next() mysql root username from set

1、需要mysql驅動包:mysql-connector-java-5.1.7-bin.jar

2、  

public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://172.16.1.23:3306/jmuv3", "root", "123.com");
System.out.println("已經連接數據庫");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from users limit 10");
while (rs.next()) {
System.out.println(rs.getString("username"));
}
} catch (Exception e) {
e.printStackTrace();
}

}

mysql 數據庫連接