Home  >  Article  >  Database  >  连接数据库

连接数据库

WBOY
WBOYOriginal
2016-06-07 15:41:291328browse

1.加载驱动 如:( DriverManager.registerDriver(new com.mysql.jdbc.Driver()); ) 2、创建与数据库的链接 如:Connection con=DriverManager.getConnection(url, user, password); 3、得到用于向数据库发送sql语句的 statement 如: Statement st=con.cre



1.加载驱动

如:(DriverManager.registerDriver(new com.mysql.jdbc.Driver());

2、创建与数据库的链接

如:Connection con=DriverManager.getConnection(url, user, password);

3、得到用于向数据库发送sql语句的 statement

如:Statement st=con.createStatement();

4、向数据库发sql,并得到代表结果集的resultset

如:String sql="select id,name,password,email,birthday from users";


5、从resultset获取数据

如:ResultSet set=st.executeQuery(sql);

6、关闭链接、释放资源

 如:   set.close();
        st.close();
        con.close();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn