Druid是一款快速、灵活的分布式数据库
MySQL是一种关系型数据库管理系统,MySQL具有速度快、可靠性高和易于使用的特点
使用Druid连接MySQL,你会发现MySQL的性能非常的优秀。
public class DruidMySQLTest {public static void main(String[] args) throws Exception {DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName("com.mysql.jdbc.Driver");dataSource.setUrl("jdbc:mysql://localhost:3306/test_db");dataSource.setUsername("root");dataSource.setPassword("root");Connection conn = dataSource.getConnection();PreparedStatement preparedStatement = conn.prepareStatement("select * from users");ResultSet resultSet = preparedStatement.executeQuery();while (resultSet.next()) {System.out.println(resultSet.getString("username"));}resultSet.close();preparedStatement.close();conn.close();}}
通过上述代码,我们使用Druid连接MySQL数据库并执行查询语句,实现了对MySQL数据库中数据的查询和读取
最后需要注意的是,Druid虽然能够提高MySQL的性能,但在使用Druid连接MySQL时需要根据具体情况进行调优和优化,以充分发挥Druid在MySQL中的优势。