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
  • 热门搜索
    法律进校园手抄报 法制伴我行手抄报 关于祖国在我心中的手抄报 手抄报名字 快乐阅读手抄报内容 初一历史手抄报 历史手抄报资料 节约用水手抄报大全 世界地球日手抄报图片 读书的手抄报图片