I have inherited a VM (linux OS) from someone. It has a java app "bob" deployed/running inside of tomcat and oracle 11.2.0 database. I wrote a simple db connection in beanshell (lightweight of java) as following example and it executed fine however a question came to my mind.
Connection con = DriverManager.getConnection("jdbc:oracle:thin:hostname:1521:sidname","username","password");
I noticed that ojdbc14.jar found /somepath/tomcat/webapps/bob/WEB-INF/lib/ojdbc14.jar AND from oracle installation /somepath/oracle/product/11.2.0/xe/jdbc/lib/{ojdbc5.jar,ojdbc6_g.jar,ojdbc6.jar} three ojdbc jar files found.
Which jar file in this case thin driver used in order to make database connection and successfully run sql query statement?
You should get rid of ojdbc14.jar and jdbc5.jar. The first one is intended for Java 1.4, the second one is intended for Java 5 (unless you actually use these outdated, non-supported Java versions).
If you are using Java7 then you should use ojdbc7.jar. If you are still using the (un-supported) Java 6, you should use ojdbc6.jar.
Note that the number in the file name only denotes the Java version, not the driver's version. To get that you would need to look at the MANIFEST.MF or use DatabaseMetaData.getDriverVersion()
Regarding the class loading in Tomcat:
Tomcat loads classes from either $CATALINA_HOME/lib, $CATALINA_HOME/lib/ext or in one of the deployed webbaps in the WEB-INF/lib directory.
So in your case, the outdated, obsolete /somepath/tomcat/webapps/bob/WEB-INF/lib/ojdbc14.jar is being used.
You should replace with an up-to-date version.
Related
I am preparing to use jdbc for the first time and am in the process of installing the jdbc driver for MySQL.
However, it is unclear to me which of these files to move to the WEB_INF/lib folder in Eclipse. They both seem to contain the same content and are included together in the downloaded zip file for the MySQL connector.
I have searched everywhere but have been unable to find any documentation to explain which of these files to use.
I thought you were joking, but I just downloaded the zip from https://dev.mysql.com/downloads/connector/j/ and, indeed, it contains both.
The mysql-connector-java-5.1.46.jar and mysql-connector-java-5.1.46-bin.jar are binary identical, except for the META-INF/INDEX.LIST (which contains the actual jar filename). I have unzipped both and compared them using kdiff3.
In short: you can use either: whatever you prefer.
This change is mentioned in CHANGES as:
- Fix for Bug#27231383, PROVIDE MAVEN-FRIENDLY COMMERCIAL PACKAGES WITHOUT "-BIN".
Interestingly, there is no bug 27231383 in the MySQL bug tracker (the number is too high for the 'normal' bugs listed), so maybe it is from another system within Oracle.
In addition, the online Connector/J 5.1.46 release notes mentions:
The bundle for Connector/J 5.1 delivered by Oracle now contains an
additional jar package with the name mysql-connector-java-5.1.ver.jar
(mysql-connector-java-commercial-5.1.ver.jar for commercial
bundles). It is identical with the other jar package with the original
package named mysql-connector-java-5.1.ver-bin.jar
(mysql-connector-java-commercial-5.1.ver-bin.jar for commercial
bundles), except for its more Maven-friendly file name. (Bug #27231383)
Presumably, given the closer match to Maven naming conventions, this makes it easier to install the library in local/company Maven repositories (eg if you don't want, or legally can't, use Maven Central).
But to repeat: they are the same, and you can use either one.
I have to create some reports using LibreOffice. I need to connecto a Firebird database using JDBC. I installed the driver (adding it to the classpath) and configured my connection to use
firebirdsql://server:alias
org.firebirdsql.jdbc.FBDriver
when I test the class I get this error:
"could not load driver class org.firebirdsql.jdbc.FBDriver"
javax/resource/ResourceException
I tried in another machine and got the same message. Is there anything extra that should be added to classpath? What I´m missing here? I have both JRE and JDK installed and I´m using the first located in C:\Program Files(x86)\Java\jre7. There is no classpath environment variable defined nor global or for the user
The above continues to be correct for Jaybird 4.0. Here are instructions in a little more detail, based on Debian 10. This is for an existing Firebird database that you can access already (i.e. can connect to and have an established username and perhaps pw).
Start LibreOffice but not Base - use Calc or just the general LibreOffice icon. Go to Tools, Options, LibreOffice and click on Advanced (in the top section, not in the Base options). Check the version number of the installed JRE. Leave the Advanced window open.
Download the corresponding version of the Jaybird zip file and unpack it. As pointed out by Mark Rotteveel in the original answer, jaybird has a dependency which may mean the bare jar file won't work. The simplest way around that is to use the "full" jar file:
jaybird-full-4.0.0.java11.jar
You may wish to move it into /usr/share/java for consistency but will probably need root permissions to do so.
Back in LibreOffice, click on the Class Path button in the Advanced window, then on Add Archive and add the .jar file. Close the Advanced window and restart LibreOffice.
Connecting: start LO Base. The Database Connect Wizard will appear. Select
"Connect to an existing database". Specify JDBC as the driver and click Next.
Base supplies the jdbc: portion of the connect string, so add
firebirdsql:oo://host[:port]//<path to database file>
So, for example:
firebirdsql:oo://localhost:3050//home/dave/Firebird/employee.fdb
Note two occurances of "//" when using a full path.
When using an alias, there's only one set:
firebirdsql:oo://localhost:3050/employee
The JDBC driver class is:
org.firebirdsql.jdbc.FBDriver
Click Test Class to confirm that it is working. If not, retrace the steps above. The class test is independent of the connection string so no need to fill in both as you troubleshoot.
From that point on it should be self-evident. You'll end up with a .odb file that you can use to create Views, Reports, etc. on the industrial-strength Firebird back end.
Jaybird has a required dependency on JCA (Java Connector Architecture), specifically JCA 1.5 (although newer should work as well), as documented in the Jaybird 2.2.5 releasenotes,
This means you need to include either connector-api-1.5.jar (from the lib folder) on the classpath, or you need to use jaybird-full-2.2.5.jar as that includes the classes from connector-api-1.5.jar.
Also your url is incorrect on two things: The format of the url is
jdbc:firebirdsql[:<subprotocol>]://<host>[:<port>]/<path-or-alias>
Which mean that :alias is wrong (it should be /alias). And as also remarked by Gord Thompson in the comments, you need to use the subprotocol oo, so you need to use protocol prefix jdbc:firebirdsql:oo to address difference in interpretation on JDBC, as also documented here. So your url should probably look like:
jdbc:firebirdsql:oo://server/alias
I'm using the code from this tutorial for using MXJ to "embed" MySQL in my java application. However, I'm getting this exception when running the code:
Exception in thread "main" java.util.MissingResourceException: Resource '5-5-9/Windows_7-amd64/mysqld.exe' not found
This happens when I reach this line in the tutorial:
mysqldResource.start("test-mysqld-thread", database_options);
I'm running in Eclipse and I have the 4 following jars added to my build path, since this link says I need them:
mysql-connector-java-5.1.18-bin.jar
mysql-connector-mxj-gpl-5-0-12-db-files.jar
mysql-connector-mxj-gpl-5-0-12.jar
aspectjrt-1.6.9.jar
I'm not sure what I'm missing here. Any tips?
MXJ doesn't come ready for use with Windows 7 64 bit. Using this bug ticket, I found what I needed to do.
Once the files are downloaded and extracted from the zips, unjar mysql-connector-mxj-gpl-5-0-12-db-files.jar and add a line to platform-map.properties file inside:
Windows_7-amd64=Win-x86
Save, and re-jar. Works like a charm!
Actually it's never a good idea to mess up with the jar files, cause whenever you upgrade to a newer version you'll need to remember to redo this fix again. The answer is correct, but you just need to create platform-map.properties file with this inside:
Windows_7-amd64=Win-x86
and add it to your classpath.
For anyone who has the same issue on MacOS Catalina, you can follow the README.md in my repo (https://github.com/pengyue/mysql-connector-mxj-mac-os-catalina), which has the 64 bits executables for MacOS Catalina, and this improved connector works on Catalina.
To explain what I have done:
Download the 64 bits executables from MySQL to the folder 5-5-9
Add the platform mapping for 64 bits MacOS in platform-map.properties
Create a jar by using jar cvf mysql-connector-mxj-db-files-5.0.12.jar .
Replace the jar in your mvn settings folder ~/.m2/repository/mysql/mysql-connector-mxj-db-files/5.0.12/ with the jar you just created.
This solution works fine for my projects, Unfortunately I could not find a github for the mysql-connector-mxj, as it is deprecated and not maintainable anymore.
The other option is to use wix-embedded-mysql(https://github.com/wix/wix-embedded-mysql) instead of mysql-connector-mxj, but this probably requires some code changes in your projects.
I haven't worked with Java in about 10 years, so it's very probable I'm doing something elementary wrong here...
I am writing a "server-side extension" for SmartFoxServer (SFS). In my login script, I need to make a connection to MS SQL Server, which I am attempting to do using JDBC. I have tested the JDBC code in my debug environment, and it works fine.
BUT
When I put the server-side extension in the SFS "extensions" folder (as per spec), I'm getting a NoClassDefFoundError thrown - clearly SFS can't find the required JAR (sqljdbc4.jar). I have tried putting this JAR in my classpath; I tried including it in my Eclipse project - but for some reason, SFS adamantly refuses to accept the existence of this JAR.
What am I doing wrong?
I have no experience with the product you mention but many years of Java experience.
Have you tried putting the sqljdbc4.jar in the same location as your server-side extension (the extensions 'directory') ? You will likely have to restart SFS after this.
I am running a series of JUnits using Apache ANT using JDK 1.5.
All JUnits that use an Oracle JDBC driver give the UnsatisfiedLinkError shown below.
What native library is it looking for and how do I solve this? What should the PATH variable contain?
java.lang.UnsatisfiedLinkError: oracle/jdbc/driver/T2CConnection.t2cGetCharSet([CI[CI[CI[CII[SLoracle/jdbc/driver/GetCharSetError;)S
at oracle.jdbc.driver.T2CConnection.getCharSetIds(T2CConnection.java:2957)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:320)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:361)
at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:142)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:79)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:595)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:196)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:114)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:77)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:59)
at oracle.jdbc.pool.OracleConnectionCacheImpl.getNewPoolOrXAConnection(OracleConnectionCacheImpl.java:401)
at oracle.jdbc.pool.OracleConnectionCacheImpl.setMinLimit(OracleConnectionCacheImpl.java:752)
Resolved!
It was actually an out-of-date ojdbc14.jar file causing this issue. All I did was update it and the problem is fixed now. The classes file
Thanks
Had this one, you should add classes12.jar or classes13.jar to your classpath (not sure about the name, it's been over a year, google these...)
"Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native. "
Means that it is looking for a DLL/so -- you probably are using THICK driver ? JDBC 2 driver ?
If yes, then you might want to add OCI.DLL, etc.
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
Also, make sure the jar in the classpath is the same one as is in $ORACLE_HOME/jdbc/lib... overwrite the Eclipse one with the Oracle one if necessary.
If this doesn't work it would help to know which version of Oracle you're running since this will affect whether you should be using classes12.jar or ojdbc14.jar
Had the same problem; resolved by changing the connection url from jdbc:oracle:oci:#//localhost:1521/service_name to jdbc:oracle:thin:#//localhost:1521/service_name