1, three-tier framework:
Presentation Layer:
It is used to display data
Business Layer:
Dealing with business needs
Persistence:
That interact with the database
2, JDBC database operation
public static void main (String [] args) { Connection Connection = null ; the PreparedStatement the preparedStatement = null ; the ResultSet the resultSet = null ; the try { // load database driver the Class.forName ( "com.mysql.jdbc.Driver" ); // access to the database through the drive link management class Connection = the DriverManager .getConnection ( "? jdbc: MySQL: // localhost: 3306 / characterEncoding the mybatis = UTF-8", "RO OT", "root"); // define the sql statement indicates? placeholder String sql = "select * from user where username = ?" ; // Get pretreatment Statement the preparedStatement = Connection.prepareStatement (sql); // set the parameters, the first parameter is a parameter in the sql statement number (starting from 1), the second parameter is set by the parameter value preparedStatement.setString ( 1, "Wang Wu" ); // sent to the database sql executed query, the result set the resultSet = PreparedStatement.executeQuery (); // iterate query result set the while (ResultSet.next ()) { System.out.println (resultSet.getString ( "ID") + "" + resultSet.getString ( "username" )); } } the catch (Exception E) { e.printStackTrace (); } the finally { //释放资源 if(resultSet!=null){ try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); }
}
if(preparedStatement!=null){ try { preparedStatement.close(); } catch (SQLException e) { e.printStackTrace(); }
}
if(connection!=null){ try { connection.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
}
}
}
to be continued. . . .