jdbc例子

public class ConnMysql {
	public static void main(String[] args) throws ClassNotFoundException, SQLException
	{
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3306/test";
		try(
			
			Connection cnn = DriverManager.getConnection(url, "root", "123");
			Statement stmt = cnn.createStatement();
			ResultSet rs = stmt.executeQuery("select * from user"))
		{
			while(rs.next())
			{
				System.out.println(rs.getInt(1)+"	"
			+rs.getString(2)+"	"+rs.getString(3)+"	"+rs.getString(4));

			}
		}
	}
}
原文地址:https://www.cnblogs.com/masterlibin/p/4780471.html