[Microsoft][ODBC Driver Manager]无效字符串或缓冲区长度异常

时间:2022-05-07 17:13:49

this is part of my code my code:

这是我的代码我的代码的一部分:

  Connection dbcon=null;
    Statement stm;
    ResultSet rs;
    ResultSetMetaData metadata;
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (java.lang.ClassNotFoundException e) {
        System.out.print("ClassNotFoundException: ");
            System.out.println(e.getMessage());         
        }
    try {
       dbcon = DriverManager.getConnection("jdbc:odbc:Bus_Info");
       stm = dbcon.createStatement();
        rs = stm.executeQuery("select distinct number, name, min(Stop_Times.departure_time), max(Stop_Times.departure_time) from Routes, Stop_Times, Stops, trips, Calendar where(stops.stop_name like'ΣΟΝΙΑ' and Stops.stop_id=Stop_Times.stop_id and Stop_Times.trip_id=trips.trip_id and trips.route_id=Routes.route_id and trips.direction='outbound' and sunday=1 and Calendar.service_id=trips.service_id)group by number, name");

        metadata = rs.getMetaData();
        int columns = metadata.getColumnCount();
    System.out.printf("%s\t%s\t%s\t%s", "ΑΡΙΘΜΟΣ ΓΡΑΜΜΗΣ",
                          "ΟΝΟΜΑ ΓΡΑΜΜΗΣ", "ΧΡΟΝΟΣ ΔΥΙΕΛΕΣΗΣ ΠΡΩΤΟΥ ΔΡΟΜΟΛΟΓΙΟΥ",
                          "ΧΡΟΝΟΣ ΔΙΕΛΕΥΣΗΣ ΤΕΛΕΥΤΑΙΟΥ ΔΡΟΜΟΛΟΓΙΟΥ");
    System.out.println();

    while(rs.next()) {

        System.out.printf("%s\t%s\t%s\t%s\n", rs.getString("number"), rs.getString("name"),
                         rs.getString("min(Stop_Times.departure_time)"),
                         rs.getString("max(Stop_Times.departure_time") );

    }
    rs.close();
    stm.close();
        dbcon.close(); 

} catch (SQLException e) {
        System.out.print("SQLException: ");
        System.out.println(e.getMessage());
}

the problem here is that when i want to display two or more columns, i get this message:

这里的问题是,当我想要显示两个或更多列时,我得到如下信息:

"[Microsoft][ODBC Driver Manager] Invalid string or buffer length exception "

"[Microsoft][ODBC Driver Manager]无效字符串或缓冲区长度异常"

what am i doing wrong? thanks in advance!

我做错了什么?提前谢谢!

3 个解决方案

#1


3  

I would comment but I don't have enough reputation.

我愿意评论,但我没有足够的声誉。

It shouldn't have to do with how many columns you are trying to print. It just doesn't like the format of at least one of the strings you are fetching. Try to print only the name column and see if it works. If not, then it's probably not being decoded correctly.

它不应该与你要打印多少列有关。它只是不喜欢您正在获取的至少一个字符串的格式。尝试只打印name列,看看它是否有效。如果不是,那么它可能没有被正确地解码。

If this is the case, go to your ODBC Data Source Administrator, select the relevant Driver from User DSN or System DSN, click on Configure and change the encoding there. If that doesn't work, try updating/downgrading your Driver. (I have had the same issue and updating my 4D Driver from v13 to v14 fixed it).

如果是这种情况,请转到ODBC数据源管理员,从用户DSN或系统DSN中选择相关驱动程序,单击Configure并更改那里的编码。如果不行,试着更新/降低你的驱动程序的等级。(我也遇到过同样的问题,把我的4D驱动从v13更新到v14,修正了这个问题)。

#2


1  

this is a java bug, update to java 1.7.60 at least

这是一个java bug,至少更新为java 1.7.60

#3


0  

I was having this issue with 64-bit Java 7 update 67. It's working for me on a different 32-bit machine using the same version of the JRE. It might work to switch to the 32 bit JRE.

我正在使用64位Java 7更新67。它在使用相同版本的JRE的另一台32位机器上工作。切换到32位JRE可能有用。

The 32 bit Access 2010 ODBC driver cannot be installed if you have 64 bit Office installed, so I can't try the 32 bit JVM on the same machine.

如果安装了64位的Office,则无法安装32位2010 ODBC驱动程序,因此我无法在同一台机器上尝试32位JVM。

#1


3  

I would comment but I don't have enough reputation.

我愿意评论,但我没有足够的声誉。

It shouldn't have to do with how many columns you are trying to print. It just doesn't like the format of at least one of the strings you are fetching. Try to print only the name column and see if it works. If not, then it's probably not being decoded correctly.

它不应该与你要打印多少列有关。它只是不喜欢您正在获取的至少一个字符串的格式。尝试只打印name列,看看它是否有效。如果不是,那么它可能没有被正确地解码。

If this is the case, go to your ODBC Data Source Administrator, select the relevant Driver from User DSN or System DSN, click on Configure and change the encoding there. If that doesn't work, try updating/downgrading your Driver. (I have had the same issue and updating my 4D Driver from v13 to v14 fixed it).

如果是这种情况,请转到ODBC数据源管理员,从用户DSN或系统DSN中选择相关驱动程序,单击Configure并更改那里的编码。如果不行,试着更新/降低你的驱动程序的等级。(我也遇到过同样的问题,把我的4D驱动从v13更新到v14,修正了这个问题)。

#2


1  

this is a java bug, update to java 1.7.60 at least

这是一个java bug,至少更新为java 1.7.60

#3


0  

I was having this issue with 64-bit Java 7 update 67. It's working for me on a different 32-bit machine using the same version of the JRE. It might work to switch to the 32 bit JRE.

我正在使用64位Java 7更新67。它在使用相同版本的JRE的另一台32位机器上工作。切换到32位JRE可能有用。

The 32 bit Access 2010 ODBC driver cannot be installed if you have 64 bit Office installed, so I can't try the 32 bit JVM on the same machine.

如果安装了64位的Office,则无法安装32位2010 ODBC驱动程序,因此我无法在同一台机器上尝试32位JVM。