For JDBC Operations database steps:
1. Import the driver package
2. Load driver (for MySQL database, Class.forName ("com.mysql.jdbc.driver"), for SQL Serverl database, class.forname (" Com.microsoft.sqlserver.jdbc.SQLServerDriver"))
Do not know the driving class, you can find the jar package to find similar "Driver" words, can be found.
3. Get Connection
4. Obtain Statement or preparedstatement, execute the executeupdate () and executeQuery () methods, Returns the result set resultset or affects the number of rows int.
5. Close the resultset, close the statement, close the connection.
The 2nd step is enough, 3rd. 4.5-Step loop operation, so do not place the third step in the constructor method until the operation class is instantiated only once.
Reference Example:
Example 1:
private static final String dburl= "jdbc:mysql://localhost:3306/test?user=root&password=admin& Useunicode=true&characterencoding=utf-8";
This.conn=drivermanager.getconnection (Dburl);
Example 2:
private static final String dburl= "jdbc:mysql://localhost:3306/test?useunicode=true&characterencoding= Utf-8";
private static final String user= "root";
private static final String password= "admin";
This.conn=drivermanager.getconnection (dburl, user, password);
Example 3:
private static final String dburl= "Jdbc:sqlserver://localhost:1433;databasename=db_test;user=sa; password=123456";
Database Operations Classes