• 数据库02


    这里只演示java-数据库的基本操作,在此基础上,再随便找本相关的参考书即可完成数据库其他基本操作。。。

    package org.lxh.demo17.connectdemo;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    public class ResultSetDemo01 {
      public static final String DBDRIVER = "com.mysql.jdbc.Driver";
      public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
      public static final String DBUSER = "root";
      public static final String DBPASS = "xyzk123";
      public static void main(String[] args) throws Exception{
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        String sql = "SELECT empno,ename,job FROM t_dept";
        Class.forName(DBDRIVER);
        conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        while(rs.next()){
          int empno = rs.getInt("empno");
          String ename = rs.getString("ename");
          String job = rs.getString("job");

          System.out.println("编号" + empno + ";");
          System.out.println("姓名" + ename + ";");
          System.out.println("职业" + job + ";");
          System.out.println(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
        }
        rs.close();
        stmt.close();
        conn.close();
      }

    }

  • 相关阅读:
    P 算法与 K 算法
    Linux 下指定端口开放访问权限
    二叉树的序列化和反序列化
    Linux 下模拟制作块设备并挂载
    累加和为 K 的子数组问题
    Linux 下搭建 Hive 环境
    分割数组的最大值问题
    Morris 遍历实现二叉树的遍历
    Linux 下搭建 HBase 环境
    Linux 下配置 hosts 并设置免密登录
  • 原文地址:https://www.cnblogs.com/XuGuobao/p/7050743.html
Copyright © 2020-2023  润新知