jdbc联接数据库

JDBC——java database connectivity

添加jar包支持

①配置pom.xml文件——dependencies,获取地址:http://mvnrepository.com/,或者:https://search.maven.org/

②官网下载支持包,在webapp文件夹下WEBINF文件夹新建lib文件夹,转入jar包文件

java代码连接数据库

一,反射形式添加驱动,Class.forName(com.mysql.jdbc.Driver);

二,获取连接connection——DriverManager.getConnection(jdbc:mysql://localhost:3306/dbname,username,password);

三,执行sql查询语句——先创建sql执行线程,connection.createStatement,然后用线程executeQuery(sql查询语句);

四,结束线程——destory

你可能感兴趣的:(jdbc联接数据库)