首页 新闻 搜索 专区 学院

Java 做GUI出现如下报错,求大佬帮助

0
[待解决问题]

在做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)

问题补充:

在网上搜的时候找到了这样一个讨论(地址:https://stackoverflow.com/questions/68376293/java-lang-nullpointerexception-cannot-invoke-java-sql-statement-executequerys)
然后我就加了这么条语句
接下来报错就成了这:Exception in thread "main" java.lang.NoClassDefFoundError: Logon
at StudentMain.main(StudentMain.java:5)
Caused by: java.lang.ClassNotFoundException: Logon
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more

求大佬帮忙

愚生浅末的主页 愚生浅末 | 菜鸟二级 | 园豆:215
提问于:2021-12-13 23:04
< >
分享
所有回答(1)
0

参考一下
https://docs.microsoft.com/zh-cn/sql/connect/jdbc/step-3-proof-of-concept-connecting-to-sql-using-java?view=sql-server-ver15#step-2-execute-a-query

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();
        }
slowstart | 园豆:520 (小虾三级) | 2021-12-14 09:13

好的 好的 非常感谢您的回复

支持(0) 反对(0) 愚生浅末 | 园豆:215 (菜鸟二级) | 2021-12-14 09:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册