解决 jdbcUrl is required with driverClassName

终于解决了。
jdbcUrl is required with driverClassName

我在写瓦力老师的寻屋项目,前两节就搞的我好痛苦。由于瓦力老师用的spring-boot依赖是1.xx多。我用的是2.2.5.RELEASE

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

所以很多东西都变了。
这个错误主要是多数据源引用不明确引起的。
后面配置多数据源时,即 JPA 和H2。在测试H2测试的时候一直报错。
即使我加了这句

#一般情况下走dev(开发)配置,所以我们可以把一些公共配置放到dev配置下,一些个性配置可以分开放
spring.profiles.active=dev

也没有用。
后面在spring网站配置多数据源的时候看到了解决方案。
下面是spring提供的一些信息:
9.9.2. Configure Two DataSources
If you need to configure multiple data sources, you can apply the same tricks that are described in the previous section. You must, however, mark one of the DataSource instances as @Primary, because various auto-configurations down the road expect to be able to get one by type.

If you create your own DataSource, the auto-configuration backs off. In the following example, we provide the exact same feature set as the auto-configuration provides on the primary data source:

@Bean
@Primary
@ConfigurationProperties("app.datasource.first")
public DataSourceProperties firstDataSourceProperties() {
    return new DataSourceProperties();
}

@Bean
@Primary
@ConfigurationProperties("app.datasource.first.configuration")
public HikariDataSource firstDataSource() {
    return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}

@Bean
@ConfigurationProperties("app.datasource.second")
public BasicDataSource secondDataSource() {
    return DataSourceBuilder.create().type(BasicDataSource.class).build();
}
firstDataSourceProperties has to be flagged as @Primary so that the database initializer feature uses your copy (if you use the initializer).

Both data sources are also bound for advanced customizations. For instance, you could configure them as follows:

app.datasource.first.url=jdbc:mysql://localhost/first
app.datasource.first.username=dbuser
app.datasource.first.password=dbpass
app.datasource.first.configuration.maximum-pool-size=30

app.datasource.second.url=jdbc:mysql://localhost/second
app.datasource.second.username=dbuser
app.datasource.second.password=dbpass
app.datasource.second.max-total=30

You can apply the same concept to the secondary DataSource as well, as shown in the following example:

@Bean
@Primary
@ConfigurationProperties("app.datasource.first")
public DataSourceProperties firstDataSourceProperties() {
    return new DataSourceProperties();
}

@Bean
@Primary
@ConfigurationProperties("app.datasource.first.configuration")
public HikariDataSource firstDataSource() {
    return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
}

@Bean
@Confi
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 这个错误信息提示缺少jdbcurldriverclassname参数。在使用JDBCJava数据库连接)连接数据库时,必须提供这两个参数。 jdbcurl参数是指数据库的URL,它描述了连接数据库所需的所有信息,如主机名、端口号、数据库名称、用户名和密码等。 driverclassname参数是指数据库驱动程序的类名,它是用于连接特定类型的数据库的类。 因此,如果出现"jdbcurl is required with driverclassname"错误提示,需要检查程序中是否已正确设置了这两个参数。例如,如果使用MySQL数据库,应该设置如下: ``` String jdbcUrl = "jdbc:mysql://localhost:3306/mydatabase"; String driverClassName = "com.mysql.jdbc.Driver"; ``` 其中,jdbcUrl是连接MySQL数据库的URLdriverClassName是MySQL数据库的驱动程序类名。 希望这可以帮助您解决问题! ### 回答2: jdbcurl 是在使用 driverclassname 时必需的。JDBC 是一种标准的数据库访问方式,通过 JDBC 驱动可以连接到数据库并进行数据操作。在使用 JDBC 连接数据库时,需要提供 JDBC URLJDBC Driver 的类名。 JDBC URL 是用于标识数据库的连接地址,它包含了数据库的类型、地址、端口、以及其他必要的参数。通过 JDBC URL,我们能够访问到具体的数据库,并进行数据操作。 而 JDBC Driver 的类名是实现了 JDBC 接口规范的驱动程序提供商所提供的类名。这个类名会根据不同的数据库和不同的驱动程序而有所区别。在使用 JDBC 连接数据库时,需要指定具体的 JDBC Driver 类名,这样才能正确地加载驱动程序并与数据库建立连接。 因此,当我们在使用 JDBC 连接数据库时,必须提供正确的 JDBC URL 和对应的 JDBC Driver 类名。如果没有提供 JDBC URL,或者是缺少了对应的 JDBC Driver 类名,就会出现异常提醒"jdbcurl is required with driverclassname",表示需提供 JDBC URLJDBC Driver 的类名。这是因为在没有正确指定连接地址和驱动程序类名的情况下,JDBC 无法知道要连接的数据库是哪个,也无法正确加载对应的数据库驱动程序。 因此,正确设置 JDBC URL 和对应的 JDBC Driver 类名是使用 JDBC 连接数据库时的必要步骤。只有提供了这两个参数,才能正确地建立数据库连接并进行后续的数据操作。 ### 回答3: jdbcurl is required with driverclassname是指在使用JDBC连接数据库时,需要指定数据库驱动程序的类名(driverclassname)以及JDBC连接的URL(jdbcurl)。 在使用JDBC连接数据库时,首先需要加载相应的数据库驱动程序,驱动程序的类名需要通过参数driverclassname指定。每个数据库厂商都提供了自己的数据库驱动程序,如MySQL的驱动程序类名为com.mysql.jdbc.Driver,Oracle的驱动程序类名为oracle.jdbc.OracleDriver等。 而jdbcurl是指JDBC连接数据库时所使用的URL,它包含了一系列的参数以及数据库的连接信息。不同的数据库有不同的URL格式,如MySQL的URL格式为jdbc:mysql://host:port/database,Oracle的URL格式为jdbc:oracle:thin:@host:port:SID等。 在使用JDBC连接数据库时,必须同时指定驱动程序的类名(driverclassname)和JDBC连接的URL(jdbcurl),否则就会出现“jdbcurl is required with driverclassname”的错误提示。 例如,如果要使用MySQL数据库,驱动程序类名为com.mysql.jdbc.Driver,数据库的URLjdbc:mysql://localhost:3306/test,那么在连接数据库时,需要这样编写代码: Class.forName("com.mysql.jdbc.Driver"); String jdbcUrl = "jdbc:mysql://localhost:3306/test"; Connection connection = DriverManager.getConnection(jdbcUrl, username, password); 其中,Class.forName("com.mysql.jdbc.Driver")用于加载MySQL数据库的驱动程序;getConnection方法用于建立与数据库的连接,其中的jdbcUrl就是JDBC连接的URL。 总之,当在使用JDBC连接数据库时,必须同时提供驱动程序的类名(driverclassname)和JDBC连接的URL(jdbcurl),否则就会出现“jdbcurl is required with driverclassname”的错误提示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值