我在我的spring-webmvc项目中使用db4free's mysql服务器。但问题是,我无法连接到服务器并且异常是
@Qualifier
但我在'之后正确指定了端口:' ,这是我的配置java类:
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException:
Must specify port after ':' in connection string
以下是我尝试执行的示例程序
@Configuration
@ComponentScan(basePackages="org.ratajo.amaderbari")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://http://www.db4free.net:3306/myDB");
dataSource.setUsername("user");
dataSource.setPassword("pass");
return dataSource;
}
答案 0 :(得分:2)
网址看起来很奇怪:
dataSource.setUrl("jdbc:mysql://http://www.db4free.net:3306/myDB");
应该是
dataSource.setUrl("jdbc:mysql://www.db4free.net:3306/myDB");
否则它会尝试使用http作为主机名和//www.db4free.net作为端口。 (这解释了错误)。但是我还要仔细检查一下主机名,因为去主机看起来很奇怪www.something'。
OTOH jdbc url&#39>很奇怪。