- 使用的jar包有
- URL书写格式
"jdbc:mysql://外网地址/数据库"
@Test
public void testALiYun() {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
Connection connection = null;
PreparedStatement prepareStatement = null;
try {
dataSource.setDriverClass( "com.mysql.cj.jdbc.Driver" );
dataSource.setJdbcUrl( "jdbc:mysql://rm-2zek19762f13s8kbo.mysql.rds.aliyuncs.com/bank" );
dataSource.setUser("root");
dataSource.setPassword("xxxx");
connection = dataSource.getConnection();
String sql = "insert into account values(null,'pig',777)";
prepareStatement = connection.prepareStatement(sql );
prepareStatement.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally {
dataSource.close();
}
}
```