我是SQL Server的新手,我正在尝试将我的Java应用程序连接到SQL Server,实际上我从Microsoft Offical website获取了MSSQL驱动程序的JDBC jar文件 然后在我的Screenshot Here*中显示SQL Server驱动程序导入得很好,但我面临的问题是我得到了这个例外,而我非常确定我已经完成了所需的步骤。
run:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:TOSHIBA-PC;database=xxx;user=sa@TOSHIBA-PC;password=shiner151092;encrypt=true;trustServerCertificate=false;loginTimeout=30;
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at connect.main(connect.java:18)
C:\Users\toshiba\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
问题在哪里,我该如何解决?
类连接代码:
import java.math.BigDecimal;
import java.sql.*;
import java.time.LocalDate;
public class connect {
public static void main(String[] args) throws SQLException {
String connectionString =
"jdbc:sqlserver://TOSHIBA-PC;"
+ "database=xxx;"
+ "user=sa@TOSHIBA-PC;"
+ "password=shiner151092;"
+ "encrypt=true;"
+ "trustServerCertificate=false;"
+ "loginTimeout=30;";
try (Connection connection = DriverManager.getConnection(connectionString)) {
String selectSql = "SELECT * from Table_111";
try (Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(selectSql)) {
if(resultSet != null){
System.out.println("connection goes right !!!");
}
}
}
}
}