I need do start the derby server from my java application using "org.apache.derby.drda.NetworkServerControl" class.
When I try to start the server it throws an exception.
Code:
NetworkServerControl server = null;
server=new NetworkServerControl(InetAddress.getLocalHost(),1527,"user","123")
server.start(new PrintWriter(System.out));
Error:
Caused by: java.lang.SecurityException: sealing violation: package org.apache.derby.impl.store.raw.xact is sealed
Can anybody tell me the reason for this error?
You have probably Derby classes twice on your classpath. Look for Derby classes in some another jar archive and use them only once.
I was facing same problem. I was packaging my application using One Jar. One Jar has it's own class loader which could cause the issue. If you are using One Jar, Try packaging your app without One Jar and verify.
I has this problem in Squirrel. I tried to add a new Derby embedded driver and I had the error.
Then I closed Squirrel, removed derby**.jar from "c:\Program Files\squirrel-sql-3.5.0\lib\", started Squirrel and added the new driver successfully.
Related
I need do start the derby server from my java application using "org.apache.derby.drda.NetworkServerControl" class.
When I try to start the server it throws an exception.
Code:
NetworkServerControl server = null;
server=new NetworkServerControl(InetAddress.getLocalHost(),1527,"user","123")
server.start(new PrintWriter(System.out));
Error:
Caused by: java.lang.SecurityException: sealing violation: package org.apache.derby.impl.store.raw.xact is sealed
Can anybody tell me the reason for this error?
You have probably Derby classes twice on your classpath. Look for Derby classes in some another jar archive and use them only once.
I was facing same problem. I was packaging my application using One Jar. One Jar has it's own class loader which could cause the issue. If you are using One Jar, Try packaging your app without One Jar and verify.
I has this problem in Squirrel. I tried to add a new Derby embedded driver and I had the error.
Then I closed Squirrel, removed derby**.jar from "c:\Program Files\squirrel-sql-3.5.0\lib\", started Squirrel and added the new driver successfully.
I've been asked to connect an Apache Derby database to our existing MATLAB data-mining tools. I am running MATLAB R2014a (no Database toolbox)
After some research and trial and error, here's what I did:
went to http://www.java2s.com/Code/Jar/d/Downloadderbyclientjar.htm and downloaded derbyclient.jar and saved it, and unzipped it to a shared folder.
edited the text file C:\Users\tyler.davis\AppData\Roaming\MathWorks\MATLAB\R2014a\javaclasspath.txt and added full path to derbyclient.jar, saved it, restarted MATLAB.
At MATLAB command line
javaclasspath
shows "S:\SHARED...\derbyclientjar\derbyclient.jar\derbyclient.jar" at the end of the static path list. So far so good.
Next, try
driverClassName = 'org.apache.derby.jdbc.ClientDriver';
java.lang.Class.forName(driverClassName);
reports error:
Java exception occurred:
java.lang.ClassNotFoundException: org/apache/derby/jdbc/ClientDriver
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
Tried an alternative:
classLoader = com.mathworks.jmi.ClassLoaderManager.getClassLoaderManager;
driverClass = classLoader.loadClass(driverClassName);
That seemed to work, created objects "driverClass, type 1x1 java.lang.Class" and "classLoader, value 1x1 com.mathworks.jmi.ClassLoaderManager"
Then I tried
DriverManager.registerDriver(driverClass.newInstance);
which reports error
Undefined variable "DriverManager" or class "DriverManager.registerDriver".
and if I try to create a sample database using
cxnStr = 'jdbc:derby:sampleDB:create=true';
cxn = java.sql.DriverManager.getConnection(cxnStr);
I get
Java exception occurred:
java.sql.SQLException: No suitable driver found for jdbc:derby:sampleDB:create=true
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
I really don't know what I'm doing here; just copying other's code from around the web. Any suggestions on what to try next?
Since you're just getting started with Derby, can I recommend that you take an hour or two and run through the Derby tutorial: http://db.apache.org/derby/docs/10.11/getstart/cgstutorialintro.html
Also, can I recommend that you get in the habit of downloading Derby from the Apache website rather than other Internet sites? The copies of Derby on other sites are probably fine, but it seems most reliable and safest to get Derby from the Apache website: http://db.apache.org/derby/derby_downloads.html
Most of what you did in your description seems OK to me; I suspect the place where you went astray is when you unzipped derbyclient.jar itself.
Although a '*.jar' file is in fact a valid ZIP archive, you are not expected to unzip those packaged jar files. Instead, you should leave the jar as 'derbyclient.jar' and then set your CLASSPATH to include 'derbyclient.jar' as one of the entries in the CLASSPATH list.
Lastly, note that the JDBC Connection URL
jdbc:derby:sampleDB:create=true
is a correct JDBC Connection URL for the embedded configuration of Derby, not for the client-server configuration of Derby.
So even if you get a good copy of derbyclient.jar into your CLASSPATH correctly, you won't be able to use
jdbc:derby:sampleDB:create=true
Instead, you'll either have to use a client-server style JDBC Connection URL, such as:
jdbc:derby://my.server.name:1527/sampleDB
(and learn how to operate a Derby Network Server), or you'll need to switch to using the Embedded Driver (org.apache.derby.jdbc.EmbeddedDriver).
For more information about this notion of configurations, see: http://db.apache.org/derby/docs/10.11/getstart/cgsquck70629.html
And for more information on the JDBC Connection URL and the two JDBC driver classes, see: http://db.apache.org/derby/docs/10.11/getstart/cgsquck19524.html
Once you've had a chance to work through the Derby Getting Started guide, I recommend asking some follow-on questions based on what you learn during that experience.
I'm learning how to deploy a web app with Tomcat and SQL Server. I'm using the jTDS driver to connect to MS SQL Server (jtds-1.3.1.jar), but I keep running into errors when I try to create a connection to the database. The program can't seem to find the jTDS driver classes. I know there's been several questions related to this on SE, but none of the solutions seem to work.
First, I'll describe how my project is set up. TOMCAT_HOME refers to the root directory of the Tomcat server. Here's a portion of my Tomcat directory:
TOMCAT_HOME\
-lib\
-jtds-1.3.1.jar
-many other default jar files
-webapps\
-TestSite\
-index.jsp
-login.jsp
-WEB-INF\
-classes\
-com\
-testsite\
-LoginServlet.class
-ConnectionManager.class
-UserDAO.class
-UserBean.class
-lib\
-web.xml
The package for the class files are com.testsite, hence the subdirectories within the classes folder. Reading the Tomcat documentation, placing jar files in the root lib folder will allow all web apps to access them. (I've also tried putting the jar files in the webapps\TestSite\WEB-INF\lib\ directory, but get the same error).
In my web application, I'm registering the jTDS with the DriverManager in one of my classes, which is called from a servlet.:
package com.testsite;
import java.sql.*;
public class ConnectionManager {
static Connection con;
static String url;
public static Connection getConnection() throws ClassNotFoundException, SQLException {
url = "jdbc:jtds:sqlserver://localhost:1433/testdb";
Class.forName("net.sourcefourge.jtds.jdbc.Driver");
con = DriverManager.getConnection(url,"username","password");
return con;
}
}
When I start up the Tomcat server, I'm able to successfully navigate to the starting page, but when I try to login (which calls the getConnection() method), it gives the following error. Why can it not see it in the lib\ folder? How can I fix it?
java.lang.ClassNotFoundException: net.sourcefourge.jtds.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClas
sLoaderBase.java:1305)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClas
sLoaderBase.java:1157)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.trainingsite.ConnectionManager.getConnection(ConnectionManager.ja
va:22)
I realized the error was due to a hard-to-see typo. I originally misspelled sourceforge:
Class.forName("net.sourcefourge.jtds.jdbc.Driver");
It should be:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Another common typo, apparently, is mixing up jdbc and jbdc in the name.
Everything works as expected after fixing that.
I wrote a java servlet program but when i run it, It was showing the Exception java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
My code
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(url, "username", "pass");
I am using Oracle 10.2.0. I added also ojdbc14.jar and ojdbc14_g.jar.
When I give the below command to command line. I get Error: Main method not found in class oracle.jdbc.driver.OracleDriver
I added also ojdbc14.jar and ojdbc14_g.jar
When adding third party libraries to your application, you must be sure they are in the Build Path of your application. In case of web applications, every third party library must be inside the WEB-INF/lib of the application so when deployed to the server (Tomcat, JBoss, etc.) they can be recognized and loaded when running your application.
Steps to rectify (if running from command prompt)
Step 1- Copy the ojdbc6 jar file from
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib (Note- this path may differ as per the installation).
Step 2- Paste the ojdbc6 jar file in the Location
C:\Program Files\Java\jre1.8.0_45\lib\ext (Note- this path may differ as per the installation).
Step 3- Now run the programme java -cp . . It should successfully run without any error.
I have a Java project that contains 1 JApplet.
I'm able to run the Applet in desk-top mode (adding the applet to a frame in main[] method).
It doesn't work in a browser though. Getting this error:
I already signed all the jars.
I believe its related to mysql connector jar.
Any ideas?
Exception occurred: java.lang.ExceptionInInitializerError (uncaught)"thread=AWT-
EventQueue-1", java.awt.EventDispatchThread.run(), line=156 bci=152
It runs fine if I add grant all to java.policy
You should ensure:
That your applet is signed to allow for database connections.
That your mysql connector jar is available on your 'download' path just like your applet jar file.
Running the application from a webserver solved the issue.