Home > Database > Mysql Tutorial > body text

连接数据库

WBOY
Release: 2016-06-07 15:41:29
Original
1372 people have browsed it

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();

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template