JDBC API入门

 时间:2026-04-25 08:15:50

1、1,导包

在eclipse工程名下穿件lib文件夹并把jar包放入,右键buildpath即可

2、2,加载驱动:Class.forName("com.mysql.jdbc.Driver");

3,获得连接:Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123");

括号中三个分别为:url,数据库用户名,密码;

3、4,获得SQL语句对象:

Statement statement = conn.createStatement();

5,执行SQL语句:

ResultSet rs = statement.executeQuery("select * from exam");

4、6,遍历结果: while (rs.next()) {

System.out.print(rs.getInt("id")+" ");

System.out.print(rs.getString("name")+" ");

System.out.print(rs.getInt("english")+" ");

System.out.print(rs.getInt("chinese")+" ");

System.out.print(rs.getInt("math")+" ");

System.out.println();

}

  • jdbc怎么使用?
  • JDBC怎么insert
  • Eclipse通过JDBC连接MYSQL
  • JDBC怎么连接MySQL
  • jdbc连接mysql
  • 热门搜索
    直发染什么颜色好看 电脑k歌需要什么设备 健康证要检查什么项目 意思相反的词语 汝是什么意思 mect是什么意思 什么是现房 金缕衣什么意思 盛气凌人的意思 发蜡什么牌子好