I have made a simple java task to make query to Ms sql DB on windows, using jdbc library.
The program runs perfectly on my eclipse. I want to use it as an exe file (so I can send it to friend so he can use that as well).
I made a jar (using the export option on eclipse) so he can execute it as an exe file on windows. The problem is when he runs the jar file on windows for some reason the results of the query are empty. I am not sure what exactly is the problem.
It's not on localhost. This is how I connect -
String connectionUrl = "jdbc:sqlserver://**.***.***.***;" + "databaseName=&&&&&&&&;user=&&&&&&&&&&&;password=$$$$$$$$";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
This is the error I get - not sure how to handle it:
java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0
I have sqljdbc4.jar and sqljdbc4.jar files on that folder.
Any thoughts?
Thanks!
It sounds like you need to modify your program so that it captures and prints out all runtime errors and warnings.
It also sounds like you want to add a "check health" feature to verify:
the program runs on your friend's PC,
the program connects to the MSSQL server,
the expected database is found on the server, and
the expected data exists in the database.
==================================================
ADDENDUM:
Thank you for updating your post and sharing the real problem:
This is the error I get - not sure how to handle it:
java.lang.UnsupportedOperationException: Java Runtime Environment
(JRE) version 1.8 is not supported by this driver. Use the
sqljdbc4.jar class library, which provides support for JDBC 4.0
It sounds like you compiled on an older version of Java (that's fine), with an older MSSQL/JDBC driver (that's fine, too) ...
... but your friend has a NEW JRE 1.8 which won't work with the new driver.
TWO SOLUTIONS:
Have your friend uninstall his JRE and then do a clean install of your Java version. For example, you can find older JRE 1.7 here:
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
Update your MSSQL driver to a current version (sqljdbc 4.2 is a good choice), verify that it works for you, then have your friend install the same MSSQL driver. You can download it here:
https://msdn.microsoft.com/en-us/library/mt484311%28v=sql.110%29.aspx
PS:
A third option - perhaps best - is for both of you to install the same version of Java and the same version of the MSSQL JDBC driver.
PPS: In the future, if you have an error message, please copy/paste it verbatim in your original post. A good error message is very often enough to resolve the problem immediately.
Related
I have a Mariadb database running on a Synology NAS which I want to access from Matlab installed on a Mac.
Here are the steps I have followed:
downloaded the MariaDB Connector/J 2.3.0 mariadb-java-client-2.3.0.jar
created a folder MyDrivers in the /Library folder and moved the driver there
added the above folder to the PATH variable
added the full path of the driver to the CLASSPATH variable
as per Matlab's tutorial, created a javaclasspath.txt file which is saved in the Matlab prefdir folder (/Users/cedric/Library/Application Support/MathWorks/MATLAB/R2018a/javaclasspath.txt). The content of the javaclasspath.txt file is /Library/MyDrivers/mariadb-java-client-2.3.0.jar
When I try to configure the data source in Matlab, I get an error message "Unable to find jdbc driver on Matlab Java class path". I believe points 3, 4 and 5 are properly done (cf outputs below).
So my questions are around the copy / paste of the .jar file of the driver. Is there anything I need to do on top of placing it in a relevant folder?
I've tried to execute it with java -jar /Library/MyDrivers/mariadb-java-client-2.3.0.jarin the Terminal. This provides: no main manifest attribute, in /Library/MyDrivers/mariadb-java-client-2.3.0.jar
Thinking it might not be an executable jar, I've tried java -cp /Library/MyDrivers/mariadb-java-client-2.3.0.jar org.mariadb.jdbc.Driver;
This returns
Error: Main method not found in class org.mariadb.jdbc.Driver, please define the main method as: public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application`
Any hints as to what to do exactly? I'm running out of tips from the researches I have done so far...
Output of env in the Terminal
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/48/d95l77ys4hv4xbfgtsh0rh1w0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.l8pI2zNcXw/Render
TERM_PROGRAM_VERSION=404
OLDPWD=/Users/cedric/.Trash/mariadb-java-client-2.2.6-sources 23.44.30/org/mariadb
TERM_SESSION_ID=396C6E65-006B-4BAF-B137-A270A36E397F
USER=cedric
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.QZhGI9ZjXf/Listeners
PATH=/Library/MyDrivers/mysql-connector-java-8.0.12/mysql-connector-java-8.0.12.jar:/Library/MyDrivers:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/cedric
LOGNAME=cedric
CLASSPATH=.:/Library/MyDrivers/mariadb-java-client-2.3.0.jar:
LC_CTYPE=UTF-8
SECURITYSESSIONID=186a8
_=/usr/bin/env
Output of javaclasspath('all') in Matlab
The last file that Matlab returns is the one of the driver: /Library/MyDrivers/mariadb-java-client-2.3.0.jar
System Specs:
Mac OS HighSierra 10.13.4
Matlab R2018a
Java -version:
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Driver Jdbc MariaDB Connector/J 2.3.0
Your attempts to run the mariadb jar show that it is fine. java is (correctly) telling you that this jar (nor the Driver class) can be treated as an application entrypoint.
Adding the lib to PATH does nothing.
adding the lib to CLASSPATH isn't recommended but can help; the only thing it does is define the classpath a java VM will use if no explicit classpath is provided. Matlab, like just about every complex java app, definitely has its own classpath. I'm not personally familiar with how matlab does things, but I'd give it 99% odds that matlab therefore completely ignores the CLASSPATH variable too.
That leaves this classpath.txt file which seems to be ignored. I don't think that's the way to configure classpath in matlab. The documentation over at https://www.mathworks.com/help/matlab/ref/javaclasspath.html should help you out. At the very least you can ask matlab about what it thinks the classpath is.
The hardest issue to solve is the non-existing one...
Thanks to rzwitserloot who confirmed the driver was well installed, i decided to go step by step. First set up a tiny java programme to test the driver which proved fine indeed, after adjustment of couple of database connection settings (port and ip). Then, despite the MATLAB message of driver not to be found, i did the same with matlab (coding instead of using the interface). This worked fine as well actually.
After that, I did try to connect via the database interface, despite the "unable to find driver" message. Connection succeeded, and the "unable to find driver" message disappeared.
As per the problems this person was having;
JDBC Connector not working
I'm running Debian 9.1
I installed Java via the package manager
I added Java to the path in /etc/config & added JAVA_HOME to the path in /etc/environment
I then installed jmeter via the package manager
I then downloaded the mysql-connector-java-5.1.44-bin.jar and copied this to /usr/share/jmeter/lib
But after all this, I still dont get the JDBC connection option under Add->Config Element within JMeter, nor do i get any options for JDBC within JMeter.
Can anyone help me as to what im doing wrong?
While I am new to JMeter, I have successfully run simple "Hello World" HTTP requests queried from a PHP Script & a NodeJS script so far.
Update
Added JMeter log by request
Jmeter log
I have no idea what the problem was with Jmeter on my Debian machine... (as prior to this I was trying to use it on Ubuntu Server, and it had the same issue as Debian);
But anyway, I just installed the Oracle JDK & JMeter for Windows, on my old Windows 7 laptop, dropped in the JDBC connector to the lib directory - & immediately it had the option for 'JDBC Connection', which never appeared on either the Ubuntu or Debian installs.
So if anyone else runs into this issue on Ubuntu or Debian ~ I might suggest trying a Windows 7 VM for running it.
Note here
This was the JMeter I installed on Windows (I didn't get it from Apache):
JMeter for Windows
For some reason I cannot find JMeter JDBC components either in Debian or in Ubuntu repositories, maybe it wasn't included by maintainers.
So instead of installing JMeter using package manager you can just download the latest JMeter version (which is JMeter 3.2 as of now while in repositories you have much older versions, 2.11/2.13) from the official website. JMeter is pure Java-based application so all you will need to do in order to be able to use it is to install Java 8 or above.
Alternative option would be downloading jmeter-jdbc JAR appropriate to your JMeter version and dropping it under /usr/share/jmeter/lib/ext folder (super-user privileges might be required), this way you will get JDBC test elements.
I'm having some issues when I try to run my program. it appears an error:
java.lang.Exception: java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0
And I already add the library in my program, using the proper jre enviroment, but it keeps sending this error when they connect to my database. I tried every solution in stackoverflow for this issue and didn't work.
I verify that is the right sqljdbc4 too, I don't know what else to do.
I'm running OpenGTS on a Windows 2012 server with Tomcat 7 and Java 1.7. I'd like to use SQL Server as I already have this installed. The specification was very clear on how to update the common.conf to point to the proper sql server database. However, when I run checkinstall.bat, (or any other DB tool for OpenGTS) I get an exception:
SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Exception in thread "main" java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
at com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:304)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.opengts.dbtools.DBConnection.getConnection(DBConnection.java:659)
at org.opengts.dbtools.DBConnection.createStatement(DBConnection.java:769)
at org.opengts.dbtools.DBConnection._execute(DBConnection.java:856)
at org.opengts.dbtools.DBConnection.execute(DBConnection.java:811)
at org.opengts.dbtools.DBConnection.execute(DBConnection.java:793)
at org.opengts.dbtools.DBFactory.tableExists(DBFactory.java:1648)
at org.opengts.tools.CheckInstall.main(CheckInstall.java:2100)
I'm pretty sure I've REMOVED or RENAMED sqljdbc.jar (perhaps renaming is not enough) in folders containing included jar files. I don't see any config file specifying this. I'm not a Java developer usually, but I feel there should be a simple thing I can do to "use" the sqljdbc4.jar that I have. I just don't know what that simple thing is... Any help would be appreciated!
It would certainly help if the SEVERE warning above which says "this" driver is not supported by JRE 1.7 would be perhaps more specific and let me know what driver "this" is...
Arg. There are too many JRE's on this machine! I found I had renamed the file in another JRE folder in lib\ext, so I removed that sqljdbc.jar file entirely. Now it is gone. Now the program works.
When I try to run Java application, I receive the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
I don't have a file ocijdbc9.* on my PC, but I have ocijdbc10.dll in %ORACLE_HOME%\bin.
%ORACLE_HOME% is correctly specified, so I think the problem is that the application is searching for the wrong version (9 instead of 10).
Both Oracle and Java Builder are freshly installed, so the problem may be in project preferences? Do you have any ideas on how to search for the place where the wrong version is specified?
You're missing a file from your java CLASSPATH.
You need to add the OCI jar to your classpath.
For my oracle 10.0.2 install on windows it's located in
%ORACLE_HOME%\jdbc\lib\ojdbc14.jar
If your application requires ocijdbc9 then you'll have to download it from somewhere and add it to the CLASSPATH. I don't know where to download it from, try the oracle site
an additional tip:
if you're using oci jdbc urls; it is always better to use the jar library of your oracle client version.
please check this address for these libraries: http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
for example if your client is Oracle 10.2.0.4, then you'd better use this client's ojdbc14.jar for java >= 1.4 and classes12.jar for java <= 1.3
note that until Oracle 11, jdbc libraries have the same names in every version such as ojdbc14.jar and classes12.jar.
You need to pass -Djava.library.path=YOUR_ORACLE_HOME\bin to the JRE as a runtime parameter
So....
java [other java switches + runtime parameters] -Djava.library.path=YOUR_ORACLE_HOME\bin run-classname
I think it is because you have not yet installed Oracle Client.
After installing it, maybe it is ok