生活随笔
收集整理的這篇文章主要介紹了
JDBC练习五
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JDBC練習五
import java.sql.*;
import java.util.*;public class JDBCTest05 {public static void main(String[] args
) {Connection conn
= null;Statement stmt
= null;ResultSet rs
= null;try{ResourceBundle rb
= ResourceBundle.getBundle("jdbc");String driver
= rb
.getString("driver");String url
= rb
.getString("url");String user
= rb
.getString("user");String password
= rb
.getString("password");Class.forName(driver
);conn
= DriverManager.getConnection(url
,user
,password
);stmt
= conn
.createStatement();rs
= stmt
.executeQuery("select * from student");while(rs
.next()){int studentid
= rs
.getInt("studentid");String studentname
= rs
.getString("studentname");System.out
.println(studentid
+ "," + studentname
);}} catch(Exception e
){e
.printStackTrace();}finally{if(rs
!= null){try{rs
.close();} catch (Exception e
){e
.printStackTrace();}}if(stmt
!= null){try{stmt
.close();} catch (Exception e
){e
.printStackTrace();}}if(conn
!= null){try{conn
.close();} catch (Exception e
){e
.printStackTrace();}}}}
}
運行結果:
總結
以上是生活随笔為你收集整理的JDBC练习五的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。