提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.mybatis.core.util; |
H |
2 |
|
|
3 |
import com.baomidou.mybatisplus.annotation.DbType; |
|
4 |
|
|
5 |
import java.sql.Connection; |
|
6 |
import java.sql.DriverManager; |
|
7 |
|
|
8 |
/** |
|
9 |
* JDBC 工具类 |
|
10 |
* |
|
11 |
* @author iailab |
|
12 |
*/ |
|
13 |
public class JdbcUtils { |
|
14 |
|
|
15 |
/** |
|
16 |
* 判断连接是否正确 |
|
17 |
* |
|
18 |
* @param url 数据源连接 |
|
19 |
* @param username 账号 |
|
20 |
* @param password 密码 |
|
21 |
* @return 是否正确 |
|
22 |
*/ |
|
23 |
public static boolean isConnectionOK(String url, String username, String password) { |
|
24 |
try (Connection ignored = DriverManager.getConnection(url, username, password)) { |
|
25 |
return true; |
|
26 |
} catch (Exception ex) { |
|
27 |
return false; |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* 获得 URL 对应的 DB 类型 |
|
33 |
* |
|
34 |
* @param url URL |
|
35 |
* @return DB 类型 |
|
36 |
*/ |
|
37 |
public static DbType getDbType(String url) { |
|
38 |
String name = com.alibaba.druid.util.JdbcUtils.getDbType(url, null); |
|
39 |
return DbType.getDbType(name); |
|
40 |
} |
|
41 |
|
|
42 |
} |