java - JDBC connection does not run with .jar file, but with eclipse project -
i'm looking @ mystery here. created java program in eclipse , established jdbc connection. code following:
import java.sql.*; public class login { public static void main(string[] args) { try { // class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); connection connection = drivermanager .getconnection("jdbc:sqlserver://localhost;databasename=testdb; integratedsecurity=true;"); //adding port 1433 doesn't make difference system.out.println("connection successful"); statement st = connection.createstatement(); resultset rs = st.executequery("select * testtable"); while (rs.next()) { line = rs.getstring(2); } } catch (exception e) { e.printstacktrace(); } } }
when i'm running within eclipse, everything's fine. database , tables good, library , authentication in java built path set , result want, namely "hello world", string in selected table.
but creating executable jar file , running throws exception "this driver not configured integrated authentication". not connect, if there error in database wouldn't matter @ point.
even more confusing fact, weeks earlier, created executable jar file , worked!
os: windows vista home premium x86 (i know, win7 lappy broken)
jdbc driver location: "c:\sqljdbc_4.0\enu\sqljdbc4.jar"
native library location: "c:\sqljdbc_4.0\enu\auth\x86"
java version: java 7 update 17 , jdk 7 update 17
previousely, used update 21, changed check if driver reason.
so, suggestions? i'd grateful!
btw, hope sscce, because don't know how smaller , more correct make it...
check runtime classpath of eclipse, try create system level "classpath" variable , add same path. once variable set, execute in new command prompt or reload environment variables
make sure executable jar has dependency in manifest.mf necessary jars (along mainclass)
finally, practice in java make first alphabet in capital ("login" instead of "login")
Comments
Post a Comment