Java 无法在Spring中连接到MySQL

Java 无法在Spring中连接到MySQL,java,mysql,spring,spring-mvc,jdbc,Java,Mysql,Spring,Spring Mvc,Jdbc,我无法连接到数据库。我的证件是正确的。我能够使用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() fo

我无法连接到数据库。我的证件是正确的。我能够使用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;
导入java.sql.ResultSet;
导入java.sql.SQLException;
导入java.util.Collection;
导入java.util.List;
导入org.springframework.jdbc.core.jdbc模板;
导入org.springframework.jdbc.core.RowMapper;
导入org.springframework.jdbc.datasource.driverManager数据源;
导入com.mvc.interfaces.DataInterface;
导入com.mvc.objects.TransactionInfo;
公共类TransactionFoService实现DataInterface{
私有字符串信息;
私有JdbcTemplate JdbcTemplate;
公共void connect(){
//连接到数据库
DriverManager数据源dataSource=新的DriverManager数据源();
dataSource.setDriverClassName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
//setUrl(“jdbc:mysql://localhost:3306/dashboard");
setUrl(“jdbc:mysql://xx.1.1.xx:3306/dashboard");
//dataSource.setUsername(“用户名”);
//dataSource.setPassword(“admin”);
dataSource.setUsername(“用户名”);
dataSource.setPassword(“密码”);
setDataSource(数据源);
}

您已将驱动程序类名设置为
com.microsoft.sqlserver.jdbc.SQLServerDriver
,但仍在尝试连接到MySQL数据库。MySQL的驱动程序是
com.MySQL.jdbc.driver

您已将驱动程序类名设置为
com.microsoft.sqlserver.jdbc.SQLServerDriver
,但仍在尝试连接连接到MySQL数据库。MySQL的驱动程序是
com.MySQL.jdbc.driver

我也试过了,实际上它对我的同事com.microsoft.sqlserver.jdbc.SQLServerDriver有效这就是为什么我试过了,但对我来说,我两次都试过了,但都不起作用。不可能。从下载驱动程序。谢谢,Reimeus我下载了MySQL connect网站上的or-java-5.1.21-bin.jar。它在Apache lib文件夹中。我确实看到了一些其他文件,下载时有任何特殊的过程。我不认为README.txt对我有用。先做一个简单的连接测试,在类路径中没有Spring和MySQL jar。例如,Reimeus,我能够使用您给出的示例成功地连接到我的数据库。但我仍然不明白为什么我无法在我的应用程序中连接。有一个问题是jdbc jar文件在Apache库中,它是否需要在其他地方。??我也尝试过,实际上它对我的同事com.microsoft.sqlserver.jdbc.SQLServerDriver有效这就是为什么我尝试了,但对我来说,我尝试了这两种方法,但都无效。不可能。下载driver from.谢谢,Reimeus我确实从网站下载了mysql-connector-java-5.1.21-bin.jar。它在Apache lib文件夹中。我确实看到了一些其他的文件,下载是他们的任何特殊过程。我不认为README.txt对我有用。首先做一个简单的连接测试,在类路径中没有Spring和mysql jar。例如,Reimeus,我能够使用您给出的示例连接到我的数据库。但我仍然不明白为什么我不能在我的应用程序中连接。有一个问题是jdbc jar文件在Apache库中,它需要在其他地方吗。??