Error connecting Java to SQL Anywhere database

穿精又带淫゛_ 提交于 2019-12-02 06:00:32

问题


I am trying to connect a java program to a database. I have sajdbc4.jar in the build path and it worked before, but now I keep getting this error when I try to make the connection:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no dbjdbc12 in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at sybase.jdbc4.sqlanywhere.IDriver.try_load(IDriver.java:455) at sybase.jdbc4.sqlanywhere.IDriver.(IDriver.java:396) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) at java.util.ServiceLoader$LazyIterator.next(Unknown Source) at java.util.ServiceLoader$1.next(Unknown Source) at java.sql.DriverManager$2.run(Unknown Source) at java.sql.DriverManager$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.sql.DriverManager.loadInitialDrivers(Unknown Source) at java.sql.DriverManager.(Unknown Source) at Main.main(Main.java:26)

Can someome please help me? Can't find anything abount this issue online.


回答1:


For windows find this file in your computer:

dbjdbc12.dll

For linux find this file:

libdbjdbc12.so

Put the location of this file on the java.library.path either with a command line option:

java -Djava.library.path=DIRECTORYWITHDLL ...

or using System.setProperty in your code:

System.setProperty("java.library.path","DIRECTORYWITHDLL");


来源:https://stackoverflow.com/questions/32672407/error-connecting-java-to-sql-anywhere-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!