62,635
社区成员




try
{
Connection conn;
Statement stmt;
ResultSet res;
//加载Connector/J驱动
//这一句也可写为:Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立到MySQL的连接
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/information_schema",
"root", "root");
//执行SQL语句
stmt = conn.createStatement();
res = stmt.executeQuery("select * from pet");
//处理结果集
while (res.next())
{
String name = res.getString("name");
System.out.println(name);
}
res.close();
}
catch (Exception ex)
{
System.out.println("Error : " + ex.toString());
}