亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JDBC的ResultSet使用說明

 更新時間:2019年02月21日 11:48:03   作者:鴨鴨老板  
今天小編就為大家分享一篇JDBC的ResultSet使用說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

一、ResultSet[結果集]

1.表示數(shù)據(jù)庫結果集的數(shù)據(jù)表,通常通過執(zhí)行查詢數(shù)據(jù)庫的語句生成。

2.ResultSet對象保持一個光標指向其當前的數(shù)據(jù)行,最開始光標在第一行。

3.next方法將光標移動到下一行,由于在ResultSet對象中沒有更多行時返回false,可以在while循環(huán)中使用循環(huán)來遍歷結果集。

package com.jun.jdbc.resultset;
 
import java.io.FileInputStream;
import java.sql.*;
import java.util.Properties;
 
/**
 * select語句返回ResultSet,取出結果
 */
public class ResultSet01 {
    public static void main(String[] args) throws Exception {
        //通過Properties對象獲取配置文件信息
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\mysql.properties"));
        //獲取到相關值
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        //得到Statement
        Statement statement = connection.createStatement();
        //sql語句
        String sql ="select id,name,sex,borndate from actor";
        //執(zhí)行sql語句,該語句返回單個,ResultSet對象
        /*
        +----+------+-----+---------------------+
        | id | name | sex | borndate            |
       +----+------+-----+---------------------+
       |  1 | tom  | 男  | 1945-05-06 00:00:00 |
       |  2 | jack | 男  | 1986-06-07 00:00:00 |
       +----+------+-----+---------------------+
         */
        ResultSet resultSet = statement.executeQuery(sql);
        //使用while取出數(shù)據(jù)
        while (resultSet.next()){//讓光標向后移動,沒有更多就返回false
            int id = resultSet.getInt(1);//得到第一行
            String name = resultSet.getString(2);//得到第二行
            String sex = resultSet.getString(3);
            Date date = resultSet.getDate(4);
            System.out.println(id+"\t"+name+"\t"+sex+"\t"+date);
        }
        //關閉連接
        resultSet.close();
        statement.close();
        connection.close();
    }
}

二、ResultSet分析

總結

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論