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();
    }
    }
  • 相关阅读:
    ureport2 数据源配置
    ureport2 + spring boot 搭建
    alibaba
    Maven Helper
    在Idea中连接数据库并生成实体类
    Intellij jrebel 热部署 安装
    IDEA使用说明
    JPA 常用注解 (hibernate)
    vue + canvas 图片加水印
    vue——批量下载图片
  • 原文地址:https://www.cnblogs.com/huangui/p/12813500.html
Copyright © 2011-2022 走看看