I'm building a little internal tool (non-production code) that gets some stuff from our MS SQL DB. I wanted to try out NetBeans 6.9.1 so am using that.
I have this function to connect to the DB, and I have the System DSN for FAND_DEV setup as SQL Native Client.
private static Connection GetConnection() {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:odbc:FAND_DEV");
} catch (SQLException ex) {
Logger.getLogger(DAL.class.getName()).log(Level.SEVERE, null, ex);
}
return conn;
}
When I step through the code in debug mode everything is working perfectly. I am getting the expected data back from the DB with no problems.
However, when I try to run (Run Main Project in NetBeans) it is throwing an exception on the DB connection. Any help on this would be greatly appreciated.
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
at sun.jdbc.odbc.JdbcOdbcConnection.buildTypeInfo(JdbcOdbcConnection.java:1503)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:381)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.get开发者_Go百科Connection(DriverManager.java:207)
at gosDbCopy.db.DAL.GetConnection(DAL.java:53)
With MS SQL you should be able to use JDBC instead of using a JDBC-ODBC bridge. The cause could be related to this though. The cause could be because of the type of data that you are returning as well. This seems to give one example of that.
精彩评论