String driver = "com.mysql.jdbc.Driver"
// URL指向要访问的数据库名mydb
String url = "jdbc:mysql://127.0.0.1:3306/mydb"
// 用户名
String user = "root"
// Java连接MySQL密码
String password = "root"
try {
// 加载驱动
Class.forName(driver)
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password)
if(!conn.isClosed())
System.out.println("connecting to the Database Succee!")
// statement用来执行SQL语句
Statement statement = conn.createStatement()
// 要执行的SQL语句
String sql = "select * from student"
ResultSet rs=statement .executeQuery(sql)
while(rs.hasNext()){
//遍历取得结果
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)