This is my first Java ODBC application so I'm sure this is me, but this is geting aggrivating. I'm using NetBeans 7.3 and connecting a SQL Server Express 2012 Database.
I have the following code which works:
private static void processToday() { //ArrayList<ClsEmployee> empList = new ArrayList<ClsEmployee>(); //int rowCount = 0; ClsConn conn = new ClsConn(); Connection con = conn.openConn(); try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT Statement"); //rowCount = rs.getMetaData().getColumnCount(); ClsEmployee emp; while (rs.next()) { emp = new ClsEmployee(); emp.setEmpId(rs.getInt("employeeId")); emp.setRollDate(rs.getDate("vacationRollDate")); emp.setLastRoll(rs.getInt("LastYearlyUpdate")); System.out.print("Employee ID: " + emp.getEmpId()); System.out.print(" roll date: " + emp.getRollDate()); System.out.println(" last updated: " + emp.getLastRoll()); //empList.add(emp); } con.close(); } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } }
However if I uncomment int rowCount = 0; I get the following error:
Exception: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
I'm at a loss, thus the reason I'm here... thanks!
Forgot to mention if I debug it, it runs fine only if I try to "run" it does it fail...
This is my connection code:
import java.sql.*; public class ClsConn { private Connection conn; public Connection openConn() { try { conn = DriverManager.getConnection("jdbc:odbc:IntranetSql"); System.out.println("DSN Connection ok."); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } return conn; } }