gpt4 book ai didi

java - 无法调用 "com.microsoft.sqlserver.jdbc.TDSReader.peekTokenType()",因为 "tdsReader"为空

转载 作者:行者123 更新时间:2023-12-03 00:20:57 25 4
gpt4 key购买 nike

我正在尝试连接到在线数据库。有时它会给我以下错误:

Exception in thread "Timer" java.lang.NullPointerException: Cannot invoke "com.microsoft.sqlserver.jdbc.TDSReader.peekTokenType()" because "tdsReader" is null
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:61)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:26)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.processExecuteResults(SQLServerStatement.java:1279)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.processResponse(SQLServerStatement.java:774)
at com.microsoft.sqlserver.jdbc.TDSCommand.close(IOBuffer.java:7264)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.discardLastExecutionResults(SQLServerStatement.java:143)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:214)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:693)
at Interface.Player_One_Screen$1.run(Player_One_Screen.java:71)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)

我的代码中引用的唯一行如下:

rs2 = statement.executeQuery("SELECT PlayerOne FROM tblTurn");

该行是 TimerTask 的一部分,它按设定的时间间隔检查在线数据库中玩家的回合。这种情况何时发生并无规律可循。我对此类错误完全没有经验。

最佳答案

您可以调用应用程序中的 Logger 对象,这些对象会生成 LogRecord 实例,然后将其提供给 Handler 对象进行处理。为了控制处理哪些 LogRecord,Logger 和 Handler 类都使用记录级别以及可选的日志过滤器。当日志记录 Activity 完成后,Handler 对象可以使用 Formatter 对象发布日志数据。

注意: java.util.logging 框架默认将其输出写入文件。对于 JDBC 驱动程序运行的上下文,此输出日志文件必须具有写入权限。

The sections that follow detail the various logging levels andcategories that may be tracked, as well as how to enable tracing inyour application.

日志记录级别:

Every log message has a logging level associated with it. The logginglevel, which is specified by the Level class in java.util.logging,defines the significance of the log message. Enabling logging at onelevel enables logging at all subsequent levels. This section discussesthe logging levels for both public and internal logging categories.See the Logging Categories section of this article for additionalinformation on the logging categories.

日志类别:

When you construct a Logger object, you must tell it which named itemor category you want to collect log information from. Thecom.microsoft.sqlserver.jdbc driver package defines the followingpublic logging categories, which are all supported by the JDBC driver.

根据错误,需要修改SQLServerStatement.java。

  • 您必须以编程方式启用日志记录才能实现解决方案。应用程序可以将日志记录级别设置为“FINE”、“FINER”和“FINEST”。

这里是可能有助于获得北斗七星见解的引用:Tracing driver operation和 sql-docs/tracing-driver-operation.md 实时发布·MicrosoftDocs/sql-docs · GitHub

关于java - 无法调用 "com.microsoft.sqlserver.jdbc.TDSReader.peekTokenType()",因为 "tdsReader"为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68854415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com