zoukankan      html  css  js  c++  java
  • JDBC

    使用JDBC,可以在ide中通过java对数据库进行操作

    //jdbc
    //1.加载驱动
    public class jdbcFirstDemo{
    public static void main(String[] args)throws ClassNotFoundException,SQLException{
    Class.forName("com.mysql.jdbc.Driver");
    //2.用户信息和url
    //useUnicode=true&characterEncoding=utf8&useSSL=true
    String url="jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8&useSSL=true
    String usrname="root";
    String password="password"
    //3.连接成功,数据库对象  Connection 代表数据库
    Connection connection=DriverManager.getConnection(url,username,password);
    //4.执行SQL的对象Statement执行sql的对象
    Statement statement=connection.createStatement();
    //5.执行SQL的对象去执行SQL,可能存在结果,查看返回结果
    String sql="SELECT * FROM table";
    
    ResultSet resultSet=Statement.executeQuery();//返回的结果集,结果集中封装了我们全部的查询出来的对象
    while(resultSet.next()){
        System.out.println("id="+resultSet.getObject(columnLabel:"id");//列名
        
    }
    //6.释放连接
    resultSet.close();
    statement.close();
    Connection.close();
    }
    }
  • 相关阅读:
    再说LZ77压缩算法
    关于LZ77压缩算法
    Qt 简易设置透明按钮
    MFC edit 控件 自动将光标置于想要输入内容的位置
    事件和委托
    2016/06/07
    2016/04/28
    2016/4/27
    2016/04/26
    重载和重写(Overload, Override)
  • 原文地址:https://www.cnblogs.com/huangui/p/12813500.html
Copyright © 2011-2022 走看看