I tried connect to MS SQL server in testng Java project using Spring JDBCtemplate. I have placed sqljdbc42 in java build path. I"m using Java Se 1.8. I"m using window authentication when connection using SSMS. Below is my code:
try {
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dataSource.setUrl("jdbc:microsoft:sqlserver://localhost:1433;instance=KUL11N0099313\\SQLEXPRESS\\test");
dataSource.setUsername("wims\\kwong");
dataSource.setPassword("");
} catch (Exception ex) {
LogManager.logger.log(Level.INFO, "Exception: " + ex.getMessage());
}
Error Message from debug variables:
CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;instance=KUL11N0099313\\SQLEXPRESS\\test
Please help. What is the cause of the problem? Is it connection string error? Thanks in advance.
According to the driver documentation , the connection string should be of the general form
jdbc:sqlserver://[serverName[\\instanceName][:portNumber]][;property=value[;property=value]]
So you might have to remove microsoft
from your connection string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.