maven中添加加入jar包
在pom.xml的depenencies的节点下添加dependency节点
通过官网:http://mvnrepository.com/,或者:https://search.maven.org/
java代码连接
加载驱动
Class.forname("com.mysql.jdbc.Driver")
获取连接线程 连接数据库需要try-catch异常
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/kgcnews","root","root"); System.out.println("打开数据库连接!");
获取sql执行线程对象
stament = connection.createStatement();
执行SQL语句获取查询结果
rs = stament.executeQuery(sqlTwo);