配置jdbc问题 mysql与IDEA

心已入冬 提交于 2019-12-27 15:20:16

1.新建lib文件夹,将jar文件导入

2在structure中添加jar文件

3设置url时需要设置时区;

import java.sql.Connection;import java.sql.DriverManager;import java.sql.Statement;public class test01 {    public static void main(String[] args) throws Exception {//        1导入jar包//        注册驱动        Class.forName("com.mysql.cj.jdbc.Driver");//        获取数据库连接        Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ab?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false","root","");//        4定义SQL语句        String sql="update employ01 set salary=500 where id=1";//        5获取执行SQL对象;        Statement statement=connection.createStatement();//        6执行SQL语句        int count=statement.executeUpdate(sql);//        7处理结果        System.out.println(count);//        释放资源        statement.close();        connection.close();    }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!