JDBC
1.JDBC Overview
Java Database Connectivity, (Java Database Connectivity, referred to as JDBC) is the Java language in the specification for how a client program to access a database application program interface , provides methods such as query and update data in a database. JDBC is also a trademark of Sun Microsystems'. We usually say the JDBC-oriented relational database.
2. The package name
specification:
1. The general is to write down the domain of the site baidu.com => com.baidu.jdbc
2. For individuals we can com.name.xx com: Personal / Business com.jiang.jdbc
3.JDBC project creation
Manually importing packages so there are a lot of trouble maven: automatic pilot package of tools
4.JDBC source
Source: It's complicated, very troublesome, it requires patience
PS: Spring source 10 years you might write two hours of video you knock + 3.5 + understand you
4.1 Class.forName("com.mysql.jdbc.Driver");
When we point into the source code, I noticed it was a reflection
Class<?> forName(String className) 以为这个类里 有最终于数据库连接的方法
Connection connect(String url, java.util.Properties info)
4.2 DriverManager driver manager
Did not produce a statement of how the manager? = "There @see Driver class in our first step in the imported
Connection getConnection(String url,String user, String password)
info => java.util.Properties => extends Hashtable<Object,Object> => Map
info 信息:存放数据库密码账号的集合
Why should I get a connection connection because we want to pass our user name and password and address
4.3 Statement Disclaimer
Carrier Statement object is what we actually executed sql statement
Statement createStatement()
* Creates a <code>Statement</code> object for sending
* parameterized SQL statements to the database.
创建一个statement对象来发送一个sql命令给数据库
select * from .... statement
insert statement
ResultSet executeQuery(String sql) throws SQLException;
5.JDBC property
import java.sql.*; 可以把sql包所有的东西都导入进来方便使用
1.url : jdbc:mysql://localhost:3306/shop = http://www.mysql.com/shop
localhost: 3306 data port Local
The role of 2.private static final
private final is not a key role, but will be proprietary priave safer, final write is dead and will not be changing the value of other factors, so an error
If you do not write earlier is actually the default public
static: Static constants can be easily invoked