// 创建连接参数
Map<String, Object> params = new HashMap<>();
params.put("dbtype", "mysql");
params.put("host", "localhost");
params.put("port", 3306);
params.put("database", "your_database_name"); // 替换为你的数据库名
params.put("user", "your_username"); // 替换为你的数据库用户名
params.put("passwd", "your_password"); // 替换为你的数据库密码
// 连接数据库
DataStore dataStore = DataStoreFinder.getDataStore(params);
JDBCDataStore store = (JDBCDataStore)dataStore ;
Connection interconnection = store.getDataSource().getConnection();
DatabaseMetaData metaData = interconnection.getMetaData();
this.version = metaData.getDatabaseProductVersion();
思路主要还是将数据源转化为普通的数据库Connection
本文介绍了如何通过Java编程,利用JDBC连接到MySQL数据库,提供连接参数示例,并展示了如何获取数据库连接和元数据信息。
985

被折叠的 条评论
为什么被折叠?



