1. 程式人生 > >資料庫連線JDBC原理

資料庫連線JDBC原理

方法:
Statement createStatment():新建一個Statement物件,此物件可以向資料庫傳送查詢資訊
void close():關閉同資料庫的連線並釋放佔有的JDBC資源
Boolean isClose():判斷是否仍與資料庫連線Statement類作用:Statement物件用於將SQL語句傳送到資料庫中。 建立Statement物件建立了到特定資料庫的連線後,就可用該連線傳送SQL語句。Statement物件用Connection的方法createStatement建立。
Connection cn=DriverManager.getconnection(rul,”sunny”,””);
statement stmt=cn.createStatement();
為了執行Statement物件,被髮送到資料庫的SQL語句將被作為引數提供給Statement的方法
ResultSet rs=stmt.executeQuery(“select a,b,c from table2”);
使用Statement物件執行語句Statement介面提供了三種執行SQL語句的方法
executeQuery():用於產生單個結果集的語句,如:select語句