我无法连接到数据库。我的凭据是正确的。我能够使用Oracle SQL Developer进行连接。我收到以下错误。任何帮助将不胜感激。
> INFO: Loaded JDBC driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
Jul 24, 2012 2:38:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet dispatcher threw exception
java.sql.SQLException: No suitable driver found for jdbc:mysql://XX.1.1.XX:3306/dashboard
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:381)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463)
at com.mvc.services.TransactionInfoService.getData(TransactionInfoService.java:39)
at com.mvc.controllers.MainController.handleRequestInternal(MainController.java:29)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
我已经包含了Java代码以及错误,我们将不胜感激任何帮助。非常感谢你。
package com.mvc.services;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import com.mvc.interfaces.DataInterface;
import com.mvc.objects.TransactionInfo;
public class TransactionInfoService implements DataInterface {
private String info;
private JdbcTemplate jdbcTemplate;
public void connect() {
// Connect To Database
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// dataSource.setUrl("jdbc:mysql://localhost:3306/dashboard");
dataSource.setUrl("jdbc:mysql://xx.1.1.xx:3306/dashboard");
// dataSource.setUsername("username");
// dataSource.setPassword("admin");
dataSource.setUsername("username");
dataSource.setPassword("password");
setDataSource(dataSource);
}
答案 0 :(得分:7)
您已将驱动程序类名设置为com.microsoft.sqlserver.jdbc.SQLServerDriver
,但仍尝试连接到MySQL数据库。 MySQL的驱动程序是com.mysql.jdbc.Driver
。