JDBC API入门

 时间:2026-02-15 10:14:07

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
  • 热门搜索
    快乐读书手抄报内容 手抄报小插图 国防手抄报图片 安全伴我成长手抄报 法制小报手抄报 我爱我校手抄报 诚实守信的手抄报 餐桌礼仪手抄报 语文天地手抄报 幼儿园手抄报图片