java链接mysql

比喻不是很合适,但能凑合用

 

 

解释

javaweb链接数据步骤 加载JDBC驱动 Class.forName(“com.mysql.jdbc.Driver);//加载JDBC驱动
提供链接数据库URL String URL = "jdbc:mysql://localhost:3306/job"
创建数据库链接 Connection connection = DriverManager.getConnection(URL,"root","123456")
创建执行对象 Statement   statement = connection.createStatement();
执行数据库操作 ResultSet result = statement.executeQuery(sql);
处理结果集 while(result.next()) {System.out.println( result.getString(1)) }
关闭资源 result.close() ;  statement.close() ; connection.close() ;

posted on 2016-12-20 11:03  成己成物kukum  阅读(171)  评论(0编辑  收藏  举报

导航