莲莲咩 2023-03-22 21:08 采纳率: 100%
浏览 42
已结题

解决Process finished with exit code 1

idea中的web工程
代码如下:


package com.dos.util;

import java.sql.*;

public class JDBCUtil {
    private static String driverName = "com.mysql.cj.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/dormitory";
    private static String user = "root";
    private static String password = "123456";

    static {

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }


    }

    public static Connection getConnection(){
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return connection;

    }

    public static void release(Connection connection, Statement statement, ResultSet resultSet){
        try {
            if (connection != null){
                connection.close();
            }
            if(statement != null){
                statement.close();
            }
            if (resultSet != null){
                resultSet.close();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        System.out.println(JDBCUtil.getConnection());
    }
}

运行出现Process finished with exit code 1

img

有什么解决的办法?或者是因为什么出错?

  • 写回答

4条回答 默认 最新

  • Java码库 2023-03-22 21:52
    关注

    方法一:URL中加入时区

    String url = "jdbc:mysql://localhost:3306/test_db?characterEncoding=utf-8&serverTimezone=Asia/Shanghai"
    

    方法二:修改MySQL的time_zone
    需要改变数据库的配置:命令行登陆mysql,修改time_zone变量的值。

    set global time_zone ='+8:00';
    

    方法三:调整jdbc驱动的版本
    mysql-jdbc 6.0以上的版本在连接数据库时,需要在url后面指定时区。

    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>8.0.11</version>
    </dependency>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 3月30日
  • 已采纳回答 3月22日
  • 创建了问题 3月22日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。