Use of resources binder Binding attributes
The actual development is not recommended to write information to connect to the database's death Java program
//使用资源绑定器绑定属性配置 ResourceBundle bundle = ResourceBundle.getBundle("jdbc"); String driver = bundle.getString("driver"); String url = bundle.getString("url"); String user = bundle.getString("user"); String password = bundle.getString("password");
Processing the query result set
The return type
method
int executeUpdate (insert/delete/update)
ResultSet executeQUery (select)DQL
ResultSet executeQUery (select)DQL
Result set ResultSet
-
throws SQLExceptionExecutes the given SQL statement that returns a single ResultSet object.
// execute SQL String = SQL "SELECT EMPNO, ename, SAL from EMP" ; RS = stmt.executeQuery (SQL); // Method DQL is performed exclusively // process the query result set of the while (rs.next ()) { / / cursor to row data // fetch // the JDBC in all indices starting at 1, not 0 // robust written to the field name (renamed after use is renamed) acquires int EMPNO = RS. the getInt ( "EMPNO" ); String ename = rs.getString ( "ename" ); Double SAL = rs.getDouble ( "SAL" ); System.out.println (EMPNO + ","+ename+","+will); }