NoClassDefFoundError: org/aspectj/lang/Sign - java

I have been trying a simple program to connect MYSQL to my Java app. I am using Windows OS. I used an online tutorial and tried the following program in notepad:
import java.sql.*;
public class Database1{
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";
static final String USER = "root";
static final String PASS = "admin";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Creating statement...");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Employees");
System.out.println("ID NAME ");
while(rs.next()){
String id=rs.getString("ID");
String name=rs.getString("NAME");
System.out.print(id);
System.out.println(name);
}
rs.close();
stmt.close();
conn.close();
} //close try block
catch(SQLException s){ s.printStackTrace();}
catch(Exception e){e.printStackTrace();}
finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}
I was getting the error:
C:\JavaP>java -cp .;C:\JavaP\mysql-connector-java-3.1.14-bin-g Database1
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Database1.main(Database1.java:17)
Goodbye!
After hours of googling and online searching I was finally able to resolve my problem (-when location of java lib folder (C:\Program Files\Java\jdk1.8.0_05\lib in my case) is maintained in environment variables, none of the java programs could execute.)
But now I am stuck with another issue:
C:\JavaP>java -cp .;C:\JavaP\mysql-connector-java-3.1.14-bin-g.jar Database1
Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Database1.main(Database1.java:17)
Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.Signature
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more

You need to add the location of the jar file containing the class org.aspectj.lang.Signature to your classpath
like.
java -cp .;C:\JavaP\mysql-connector-java-3.1.14-bin-g.jar;C:\JavaP\aspectj.jar Database1

In fact, I think you choose the debug version jar for jdbc driver, when I download MySQL SQL driver jar and extract the zip file, it looks like below:
You should choose the jar having the name like mysql-connector-java-5.0.8-bin.jar but not mysql-connector-java-5.0.8-bin**-g**.jar in debug folder.

Here's the Manifest of the JAR that works:
Manifest-Version: 1.0
Name: org/aspectj/lang/
Specification-Title: AspectJ Runtime Classes
Specification-Version: 1.8
Specification-Vendor: aspectj.org
Implementation-Title: org.aspectj.tools
Implementation-Version: 1.8.7
Implementation-Vendor: aspectj.org
Bundle-Name: AspectJ Runtime
Bundle-Version: 1.8.7
Bundle-Copyright: (C) Copyright 1999-2001 Xerox Corporation, 2002 Palo
Alto Research Center, Incorporated (PARC), 2003-2009 Contributors.
All Rights Reserved.

Related

Is it possible to run an application from the Command Line and reference a .jar file too?

I have a simple java application that i've got running in Netbeans, show below. i've added the sqlite-jdbc.jar in Netbeans to access the database but i'd like to know if i can use the .jar from the Command Prompt and if so how? Thanks.
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import java.sql.*;
import javax.swing.*;
/**
*
* #author James
*/
public class TestProj{
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ConnectDb();
}
public static Connection ConnectDb(){
try
{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:
C:\\Users\\James\\Documents
\\NetBeansProjects\\TestProj\\TestProj.sqlite");
System.out.println("Connection opened successfully!");
Statement stat = conn.createStatement();
String sql = "SELECT kE100 FROM customers" +
" WHERE phoneNo = 873333333";
ResultSet rs = stat.executeQuery(sql);
System.out.println("name = " + rs.getString("kE100"));
conn.close();
return conn;
}catch(Exception e){
System.out.println("No Connection!");
return null;
}
}
}
C:\Users\James\Documents\NetBeansProjects\TestKamarad\src\testkamarad>javac -cp
"C:/Users/James/Desktop/Installers Etc/sqlite-jdbc-3.7.2.jar;" TestKamarad.java
C:\Users\James\Documents\NetBeansProjects\TestKamarad\src\testkamarad>java -cp "
C:/Users/James/Desktop/Installers Etc/sqlite-jdbc-3.7.2.jar;" TestKamarad
Exception in thread "main" java.lang.NoClassDefFoundError: TestKamarad (wrong na
me: testkamarad/TestKamarad)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
How to run a .jar from commandline ? It's pretty simple, just type in:
java -jar foo\bar.jar

getting java.lang.UnsatisfiedLinkError when trying to connect to oracle db

i am facing a problem getting OCI JDBC to work.
i need to use the oci driver because you cannot set a new password on logon when it has expired and is in grace time.
i use oracle 11g release 2
i downloaded the basic instantclient-basic-windows.x64-11.2.0.4.0 and unzipped it. its located in the folder
C:\Users\Yeslan to the Coa\workspace\KWIKI\instantclient_11_2\.
i have added this link as it is to the PATHsystem variable.
i set the native library location in eclipse to that path.
when i try to logon to oracle:
protected static OracleConnection con;
static String url = "jdbc:oracle:oci:#//192.168.97.10:1521/orcl";
static String user = "user";
static String pw = "password";
public final Connection openCon() {
Properties prop = new Properties();
try {
System.out.println("openCon(): URL = " + url + " username = "
+ user + " password = " + pw);
prop.setProperty("user", user);
prop.setProperty("password", pw);
con = (OracleConnection) DriverManager.getConnection(url, prop);
con.setAutoCommit(false);
System.out.println("oracle con ok");
return con;
} catch (SQLException e) {
e.printStackTrace();
String errMessage = e.getMessage();
System.out.println("oracle con not opened because: " + errMessage);
}
}
i get the following error message:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: C:\Users\Yeslan to the Coa\workspace\KWIKI\instantclient_11_2\ocijdbc11.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at oracle.jdbc.driver.T2CConnection$1.run(T2CConnection.java:3560)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.jdbc.driver.T2CConnection.loadNativeLibrary(T2CConnection.java:3556)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:269)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:165)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:53)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at at.nje.DB_FTP_Operations.ConnectOrcl.openCon(ConnectOrcl.java:76)
at at.nje.Kone.GUI.AdminFrame.<init>(AdminFrame.java:60)
at at.nje.Kone.GUI.AdminFrame$1.run(AdminFrame.java:46)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
please tell me what i am missing to do, or what i´m doing wrong.
How to set up oci jdbc on win 7 64 to connect to oracle 11g release 2

How can I shut down a Derby connection that has been made by another program?

I have written a test program that makes a Derby connection and creates the necessary tables if they do not exist. But once I run the programme I can't rerun it again because the exception I have brought. I think that I should add a finilize method to the current singletone class and close the connection there. Is it the solution?
But anyway I consider the possiblity of the program crash and exiting from the program in an abnormal manner. In that case how can I force to close the other instances of the connection to the database safely and make my own connection?
public class DBTest {
public static void main(String[] args) {
DBConnection.getInstance();
}
}
public class DBConnection {
private static DBConnection ourInstance = new DBConnection();
private Connection connection;
public static DBConnection getInstance() {
return ourInstance;
}
private DBConnection() {
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String dbName="C:/Users/Puk/IdeaProjects/DerbyTest/database/Ablauf";
String connectionURL = "jdbc:derby:" + dbName + ";create=true";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
connection = DriverManager.getConnection(connectionURL);
} catch (SQLException e) {
e.printStackTrace();
}
createTables();
}
private void createTables(){
Statement s;
try {
s = connection.createStatement();
s.execute("CREATE TABLE category ( id SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY \n" +
"\t(START WITH 0, INCREMENT BY 1), title VARCHAR(100))");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
java.sql.SQLException: Failed to start database 'C:/Users/Puk/IdeaProjects/DerbyTest/database/Ablauf' with class loader sun.misc.Launcher$AppClassLoader#1830e4a7, see the next exception for details.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
at org.apache.derby.jdbc.Driver20.connect(Unknown Source)
at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at model.DBConnection.<init>(DBConnection.java:31)
at model.DBConnection.<clinit>(DBConnection.java:12)
at test.DBTest.main(DBTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.sql.SQLException: Failed to start database 'C:/Users/Puk/IdeaProjects/DerbyTest/database/Ablauf' with class loader sun.misc.Launcher$AppClassLoader#1830e4a7, see the next exception for details.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 20 more
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database C:\Users\Puk\IdeaProjects\DerbyTest\database\Ablauf.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
... 17 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database C:\Users\Puk\IdeaProjects\DerbyTest\database\Ablauf.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source)
at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source)
at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source)
at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source)
... 17 more
Exception in thread "main" java.lang.ExceptionInInitializerError
at test.DBTest.main(DBTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.NullPointerException
at model.DBConnection.createTables(DBConnection.java:41)
at model.DBConnection.<init>(DBConnection.java:35)
at model.DBConnection.<clinit>(DBConnection.java:12)
... 6 more
Process finished with exit code 1
You cannot boot a db from multiple jvms at the same time. This is explained in the docs Derby Dev Guide
HTH
D

Wso2 ESB - Generated Java Client Error

When I generated a Java Client through the web page of wso2esb for a deployed service "Hello". In addition to the HelloServiceCallBackHandler.java and HelloServiceStub.java I created the class entitled HelloClient.java:
package org.wso2.cs.helloservices;
import java.rmi.RemoteException;
import org.wso2.cs.helloservices.HelloServiceStub.SayHello;
import org.wso2.cs.helloservices.HelloServiceStub.SayHelloResponse;
public class HelloClient {
public static void main(String[] args) {
try {
String name= new String("Test");
HelloServiceStub stub= new HelloServiceStub();
SayHello sh= new SayHello();
sh.setName(name);
SayHelloResponse resp=stub.sayHello(sh);
System.out.println("Response : "+resp);
}catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I have the following error:
<font color="red"> Exception in thread "main" java.lang.NoClassDefFoundError: javax/wsdl/extensions/soap/SOAPAddress
at org.wso2.cs.helloservices.HelloServiceStub.populateAxisService(HelloServiceStub.java:41)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:88)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:77)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:126)
at org.wso2.cs.helloservices.HelloServiceStub.<init>(HelloServiceStub.java:118)
at org.wso2.cs.helloservices.HelloClient.main(HelloClient.java:13)
Caused by: java.lang.ClassNotFoundException: javax.wsdl.extensions.soap.SOAPAddress
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more</font>
This seems to be required jars not found (This complains about wsld4j). Please add AXIS2_HOME/lib folder to your program's classpath .

i want to connect to SQL Server using Java, please find the code below and i am getting the exception as given below "Error Message"

String dburl="jdbc:sqlserver://209.18.103.198:1433;CreditDB_V2";
//Connecting to Database
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con=java.sql.DriverManager.getConnection(dburl,"700User","cred!tUser");
Thread.sleep(20000);
if (con!=null)
{
System.out.println("Database Connected Successfully");
Statement stmt=con.createStatement();
ResultSet rss=stmt.executeQuery("update User_LogDetail set LoginTime=(GETDATE()-
35), StatusId = 401 where UserId in(select userid from user_detail where UserName
in('sahooxml','gopal','psahoo7'))");
Thread.sleep(30000);
while (rss.next()) {
Object dbtime = rss.getString(1);
System.out.println(dbtime);
} //end while
con.close();
}
else
{
System.out.println("Database Failed to connect");
}
Error Message:
Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Login700.LoginTest(Login700.java:26)
at Login700.main(Login700.java:242)
The jar file containing "com.microsoft.sqlserver.jdbc.SQLServerDriver" class has to be in your classpath.

Categories