java连接mysql

在自己的blog中记录一些琐碎的学习知识,方便以后的查用,当然好。现在公司可以上网了,坚持下去。

java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql:///ext", "root", "");
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("SELECT * from user");
int id = 0;
String nam = "";
while (rs.next()) {
  id = rs.getInt(1);
  System.out.println(id);
  nam = rs.getString("user_nam");
  System.out.println(nam);
}

你可能感兴趣的:(java,sql,mysql,jdbc,ext)