Java [Microsoft][ODBC 驱动程序管理器] 无效的字符串或缓冲区长度异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20204553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:15:39  来源:igfitidea点击:

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

javasqlsql-serversqlexception

提问by theosot

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 驱动程序管理器] 无效的字符串或缓冲区长度异常”

what am i doing wrong? thanks in advance!

我究竟做错了什么?提前致谢!

回答by mmavcy

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.

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

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 中选择相关的驱动程序,单击配置并在那里更改编码。如果这不起作用,请尝试更新/降级您的驱动程序。(我遇到了同样的问题,将我的 4D 驱动程序从 v13 更新到 v14 修复了它)。

回答by jvea

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

这是一个java错误,至少更新到java 1.7.60

回答by Sarel Botha

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 位 Access 2010 ODBC 驱动程序,因此我无法在同一台机器上尝试 32 位 JVM。