- load driver
- get connection
- get statement and execute sql
- get resultSet and handle data
- close collections to database
Sample code:
Some tips:
- import JDBC API, not MySQL API, interface-oriented programming, for good maintanence.
- Recommend using properties files to save driver, url, username and password, then we can easily switch different database without changing code.
- using preparedStatement replace statement, 1) avoid sql injection 2) pre-compile for efficiency
- for date type: date of Util to date of sql,
new java.sql.Date("object".getTime());