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
有什么解决的办法?或者是因为什么出错?