在做GUI程序的时候在连接数据库的时候出现了这样的报错,经过一番查询仍然未能正确修改,希望有懂的大佬帮助一下小白。
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StudentManager
com.microsoft.jdbc.sqlserver.SQLServerDriver
Can't Find Database Driver.
SqlManager:Connecting to database...
connectDBNo suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StudentManager
SqlManager:Connect to database successful.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.sql.Statement.executeQuery(String)" because "this.Sqlstmt" is null
at SqlManager.executeQuery(SqlManager.java:111)
at AdmPanel.createStuPanel(AdmPanel.java:133)
at AdmPanel.<init>(AdmPanel.java:114)
at MyFrame.<init>(MyFrame.java:20)
at StudentMain.main(StudentMain.java:5)
求大佬帮忙
try (Connection connection = DriverManager.getConnection(connStr);
Statement statement = connection.createStatement()) {
var resultSet= statement.executeQuery("select top 100 column1 from table1");
while (resultSet.next()){
System.out.println((resultSet.getString(1)));
}
} catch (SQLException e) {
e.printStackTrace();
}
好的 好的 非常感谢您的回复