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.
Related
I had to install logisim ( a logic circuit editor) but java 5 or any newer edition was required to do so, while i also had downloaded jdk-13.0.2 in order to develop some java projects .I was given this link in order to download logisim:
http://www.cburch.com/logisim/download.html
Also, i downloaded java 8 from the following link:
https://java.com/en/download/manual.jsp?fbclid=IwAR2BoP89O7qYdbWc0Knk5tSSvymVDN-5XF9FdAKo-_OT4pLnnAG-dcxlC9M
Although logisim was succesfully installed to my computer , java stopped working. In adittion vscode reports that no jdk is installed and that classpath system variable points to 0 .
Anyway, I found out that my jdk is stored where it should be ,which means in programm files , while i realised that i had downloaded two more jdks !!! (I still dont know how these got in my computer ...).But this shouldn't really matter because the cmd programm used everytime before starting coding in java still sets the classpath and path system variables at the correct destinations .
The cmd code is the following:
set path="C:\Program Files\Java\jdk-13.0.2\bin"
set classpath=.;C:\Program Files\Java\jdk-13.0.2\lib\tools.jar
(My point is that it doesn't seem to be the above program's fault. )
I also can't find the java edition (java 8) I was supposed to have already to downloaded in order to install and operate logisim with the file explorer.
I really need to keep both logisim and vscode operanotional.
Does it mean that im able to code in java just by having jdk ? ( I wouldn't bother to download java 8 if it wasn't for logisim...).
Also whenever I try to compile a java file using cmd , I get the following error back:
An error has occurred while processing the shared archive file.
Mark mismatch while restoring from shared file.
Error occurred during initialization of VM
Unable to use shared archive.
Any ideas could be helpful.
A new path system variable must be created for the new JRE installation also (the one installed for Logisim). Separate path variables should be there for JDK and new JRE.
For example:
For JDK- D:\PROGRAM FILES\Java\jdk-15.0.2\bin
For JRE- C:\Program Files (x86)\Java\jre1.8.0_281\bin
Path system variable should point to the bin folder of wherever JRE installed.
Path system variables for JDK and JRE. SS from control panel:
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.
I have just installed the Matlab Runtime on:
Distributor ID: Ubuntu
Description: Ubuntu 15.04
Release: 15.04
Codename: vivid
You can find the Matlab runtime here in my case in installed R2015b (9.0)* (MATLAB Runtime 9.0, for R2015b, is intended to work with MATLAB 8.6, which is also R2015b).
The Matlab libraries get installed to: /usr/local/MATLAB
I am using Netbeans 8.0.2
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The error I get off my program is as follows:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the required library libmwmclmcrrt.so.9.0 on java.library.path.
This library is typically installed along with MATLAB or the MCR. Its absence may indicate an issue with that installation or the current path configuration.
The MCR version that this component is trying to use is: 9.0.
On the install of Matlab it does say:
On the target computer, append the following to your LD_LIBRARY_PATH environment variable: /usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:
I have added this line to Project > Properties > VM Options:
-Djava.library.path="/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:"
And I have added the same folders to Project > Properties > Libraries using the: Add JAR/Folder button.
I have put the following line of code into my program:
System.out.println(System.getProperty("java.library.path"));
To which I get output correctly as:
/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:
However, it continues to fail to run with the same error.
I installed IntelliJ IDEA Community edition and with no mods at all and the code just runs without any issues. I really wish to keep with Netbeans and would like to understand the issue. Any ideas?
IntelliJ has the following loaded:
/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java
-Didea.launcher.port=7532
-Didea.launcher.bin.path=/home/code/idea-IC-143.1821.5/bin
-Dfile.encoding=UTF-8
-classpath /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/cldrdata.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/dnsns.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/icedtea-sound.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/java-atk-wrapper.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/localedata.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/nashorn.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunec.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunjce_provider.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/sunpkcs11.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext/zipfs.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jce.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/jsse.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/management-agent.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/resources.jar
:/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/rt.jar
:/home/code/NetBeansProjects/CO2model/out/production/TestModelABC
:/home/code/NetBeansProjects/CO2model/TestModelABC/dist/lib/co2model.jar
:/home/code/NetBeansProjects/CO2model/TestModelABC/dist/lib/javabuilder.jar
:/home/code/NetBeansProjects/CO2model/for_redistribution_files_only/co2model.jar
:/home/code/idea-IC-143.1821.5/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain test.Startup
.
:
:/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64
:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64
:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64
:
:/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni
:/lib/x86_64-linux-gnu
:/usr/lib/x86_64-linux-gnu
:/usr/lib/jni
:/lib
:/usr/lib
java.library.path is the path that java uses to find native libraries.. An error would be caused if
There is no file called libmwmclmcrrt.so in the path
The permissions of the file libmwmclmcrrt.so is not correct
So my advice would be to run a search with name libmwmclmcrrt.so to know whether the file is in the system or not..
If found you could manually copy-paste it to this path
/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64
If already present in that path maybe you could check the file permissions..
In most of the cases the error is caused because the library isn't found..
to set java.library.path in netbeans. Select project, right click on Properties. Select Run option, Change VM options to add native library -Djava.library.path="absolute\path\to\your\library\files".
after this, you need to load the library through `System.load("absolute\path\to\your\library\files");' in static block.
like this
static {
try {
System.load("absolute\path\to\your\library\files");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
also modify the LD_LIBRARY_PATH environment variable to include the path where the matlab library is located.
export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH
I think we have a better explanation here.
In short:
Some system property is only read once when the JVM is started up, thus changing it after start-up will not make JVM load it again, so System.setProperty() will not work.
In particular, java.library.path is read-only.
So, the only way to set it, is to set %PATH% in Windows, or $LD_LIBRARY_PATH in Linux-like systems.
To set it system-wide in Linux, edit /etc/environment. If you want to set it only user-wide, check this very practical article.
LD_LIBRARY_PATH="/some/preset/path:/your/path/to/add"
Plus: in case that you don't know it, a locate libmwmclmcrrt.so.9.0 is always very helpful in this situation, specially when you may have various version of a file in different location with identical name. And /your/path/to/add is a directory.
I have a very old application (published in 2001) I am trying to get working in Windows 7/8/10. There is a setup.exe part of it that is using Java in some capacity, and not working correctly. I suspect it is using java because I decompiled the JAR file packaged with the application and there are references to several setup steps within the .java files (along with a file named setup.java). There is also a jre folder published with the application as well, running the following (dated) version:
F:\jre\bin>java -version
java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)
At first I suspected the application was using the systems environmental variables to use the currently installed version of JAVA, but I ruled that out by completely purging JAVA from the system and retesting - same results.
I next tried to simply update the folder to the latest version. As expected however, there were calls being made that were no longer supported (error message was referencing _JVM_IsVMGeneratedMethodl).
At this point I am running out of options. I could always run this application in a VM (and it works fine), but I would prefer to somehow package it in a nice streamlined way for easy distribution and install. Is there anything I can do? I was thinking something along the lines of application virtualization but still reading up on it.
It's hard to tell without "being there", but I'm guessing that the old (1.3) JVM just isn't compatible with the more modern versions of Windows.
Your best bet is probably running it against whatever version of Windows the app was originally developed on, in a VM.
If you have / can get the complete source code, you could try recompiling it with the version of Java supported on your current system. But it's probably a long-shot.
If it is containing a JRE folder, then you could skip the installer and add some batch file to launch that .jar with the specific JRE via a command of this form:
java -jar pathToYourJAR
btw, you could also consider options to convert to executable, some older are mentioned here:
How can I convert my Java program to an .exe file?
some of them may allow you to select which JRE to bundle/use
I have installed Oracle 11.2 and Java:
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
In the command line, if i try to:
java oracle.jdbc.driver.OracleDriver
Java says: impossibile to load or find oracle.jdbc.driver.OracleDriver
I have copied ojdbc5.jar, ojdbc6.jar and ojdbc6_g.jar
From oraclexe\app\oracle\product\11.2.0\server\jdbc\lib to
C:\Program Files\Java\jdk1.7.0_09\lib
If i run echo %CLASSPATH% I get:
C:\Program Files\Java\jdk1.7.0_09\lib (ie where I have copied the jar files)
Any reasons why Java can't find oracle.jdbc.driver.OracleDriver ?
You reference a folder on the classpath and expect it to load all jars in it. That is not how the classpath works, you need to reference specific jars (and normally you should NOT put third party jars inside the JDK folder).
It is also important to know that the CLASSPATH is usually ignored by java applications, except for the most basic use cases.
You can do what you try to achieve by doing:
java -cp <path-to>\ojdbc7.jar oracle.jdbc.OracleDriver
This will fail btw because OracleDriver has no public static void main(String[] args) method and therefor cannot be run like this. The normal way to use a JDBC driver is to have the driver on the application classpath, and simply specify the right driver URL. JDBC 4.0 (Java 6) or higher compliant drivers will be automatically loaded from the classpath (as specified with -cp, the Class-Path manifest entry etc).
On an unrelated note, oracle.jdbc.driver.OracleDriver is considered deprecated, use oracle.jdbc.OracleDriver instead, see Difference between Oracle jdbc driver classes?
Putting a directory on the classpath doesn't put all the jar files within that directory on the classpath. It's not clear why you've copied the Oracle jar file into your Java installation directory - I'd recommend not doing that - but you should just list the location explicitly. For example, if you've copied it into the lib directory relative to your application, you could use:
java -cp lib\ojdbc7.jar;. your.class.Name
You can use * in a -cp command line argument to find all jar files, e.g.
java -cp lib\*;. your.class.Name
or you could copy it into an "extensions" directory - but I think it's clearer to be explicit.
I also had same problem and this is what i did
I extracted ojdbc5.jar and then i copied oracle folder in extracted ojdbc5.jar and then pasted in current location where i wrote jdbc program ( not mentioning the directory as it differs from programmer to programmer), then used import oracle.jdbc.*; statement in my jdbc program as oracle.jdbc has OracleDriver in it.
Rest of the program is same
Before copying ojdbc6.jar to <jdk-home>/jre/lib/ext/, in IDEA you need to add the ojdbc6.jar file in "Structure" -> "SDK" -> "add classpath" to <jdk-home>/jre/lib/ext/ojdbc6.jar