Error to connect database in Eclipse JDBC ODBC, - eclipse

I'm looking for resolve problem with eclipse, im trying to connect to MySQL via ODBC im using java 1.7, and the same code in NetBeans, and Eclipse,
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Gtable","root","");
In NetBeans it works fine but in Eclipse returns
Exception in thread "main" java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
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 testdb2.testd.main(testd.java:11)
How can i fix it ?
I added it to build path
it did not help
Im using this now,
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("sun.jdbc.odbc.JdbcOdbcDriver found");
} catch (ClassNotFoundException cnfe) {
System.out.println("Error: sun.jdbc.odbc.JdbcOdbcDriver not found");
}
And it returns jdbcodbc not found, where can i get that ?

The issue with the Eclipse project was that it was actually running under Java 8, so the JDBC-ODBC Bridge was not available. Changing the run configuration to use a Java 7 JRE solved the problem.

If you want to do this correctly, add a folder called lib to your current project.
Download the jar for the driver and drag this jar from your file explorer in your lib folder in eclipse.
After this, right click your project folder -> java build path, look for the libraries tab and click add jars.
Browse to your jar in the lib folder and click OK. After this click ok again.
This should work :)
Try this:
Class.forName("com.mysql.jdbc.Driver");
If this doesn't work, you probably gave the wrong path.
Try searching in your referenced libraries in the package explorer view.
Just expand the jar and look for driver.class.
If this is to much work, your could try searching with shift + ctrl + r.
adjust your filter to your needs.
You need to search for the path of driver.class
I also suggest you not to use root and give it a strong password

You should open project property (alt+Enter), open menu "Deploy Assembly", and set libraries folder, where you have jdbc driver.
Something like this:

Related

java.lang.NoClassDefFoundError: org/openqa/selenium/remote/service/DriverService$Builder

I am trying to create a TestNg Maven project in Eclipse for Selenium. Here is my code :
package Edureka_Case_Study_8th.Edureka_Case_Study_8th;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CaseStudy2 {
#Test
public void basicSetup() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Sitesh\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.flipkart.com/ ");
}
}
When I try to run it, I get the following error:
[RemoteTestNG] detected TestNG version 7.3.0
FAILED: basicSetup
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/service/DriverService$Builder
at Edureka_Case_Study_8th.Edureka_Case_Study_8th.CaseStudy2.basicSetup(CaseStudy2.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(Unknown Source)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException:
org.openqa.selenium.remote.service.DriverService$Builder
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)
... 29 more
Can anybody please come up with a suggestion / solution ?
Artifacts used :
Eclipse - Version: 2020-06 (4.16.0) , Selenium - v3.141.59
Its look like issue is with Selenium Libraries. Please add all selenium jars. Follow below:
Download Selenium Client & WebDriver Language Bindings for Java from (Make sure you are downloading as per your system configuration) https://www.selenium.dev/downloads/
Unzip the file.
Open your project > Right click > Build Path > Configure Built Path > Libraries > Add External Jars
Select all jars present inside above unzipped folder ( Make sure you add libs also).
Also insure Java is installed and path for JDK is pointed under execution environment.
Go to Build Path > Configure Built Path > Libraries.
Open JRE System Libraries
And if by default selected environment is not pointing to JDK. Select Alternate JRE.
Click on Installed JREs and browse to JDK folder select.
Note : Using Same Code and above mentioned SetUp I am able to run your script.

Only in Eclipse: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

Actually I'm introducing myself into JSF. For that reason I copied the project from this location:
http://www.concretepage.com/spring-4/spring-4-jsf-2-integration-example-using-autowired-annotation
Setup:
OpenSUSE 13.2
JDK-1.8.0_77
Gradle 3.0
Spring 4
JSF-2
Apache Tomcat 8.0.33
Eclipse MARS 2 (4.5.2)
Building this project with "gradle build" and deploy it manually to Tomcat and access an URL works just fine. So this project seems to be OK.
So I try the same procedure inside eclipse with a configurated server. But as soon as I access the same URL, I'm getting an IllegalStateException (No WebApplicationContext found: no ContextLoaderListener registered?).
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.jsf.FacesContextUtils.getRequiredWebApplicationContext(FacesContextUtils.java:81)
org.springframework.web.jsf.el.SpringBeanFacesELResolver.getWebApplicationContext(SpringBeanFacesELResolver.java:90)
org.springframework.web.jsf.el.SpringBeanFacesELResolver.getBeanFactory(SpringBeanFacesELResolver.java:78)
org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:49)
com.sun.faces.el.DemuxCompositeELResolver._getValue(Unknown Source)
com.sun.faces.el.DemuxCompositeELResolver.getValue(Unknown Source)
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
org.apache.el.parser.AstValue.getValue(AstValue.java:137)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
com.sun.faces.facelets.el.TagValueExpression.getValue(Unknown Source)
javax.faces.component.ComponentStateHelper.eval(Unknown Source)
javax.faces.component.ComponentStateHelper.eval(Unknown Source)
javax.faces.component.UIOutput.getValue(Unknown Source)
javax.faces.component.UIInput.getValue(Unknown Source)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(Unknown Source)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(Unknown Source)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(Unknown Source)
javax.faces.component.UIComponentBase.encodeEnd(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
javax.faces.render.Renderer.encodeChildren(Unknown Source)
javax.faces.component.UIComponentBase.encodeChildren(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
javax.faces.component.UIComponent.encodeAll(Unknown Source)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Unknown Source)
com.sun.faces.application.view.MultiViewHandler.renderView(Unknown Source)
com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
javax.faces.webapp.FacesServlet.service(Unknown Source)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I think this exception is already seen pretty often. I've tried serveral confirmed solutions, but all of them mess up the simplicity of the project. Also the manual deployment is working, so I don't think there is something wrong with the project itself. (e.g. adding a context-listener,...)
I'm pretty sure, there is something wrong with the configuration of the server or the project inside eclipse.
I compared several settings against the standalone-tomcat:
Usage of the same JRE
configuration of project's libs and deployment-assembly
eclipse launch-configuration by ps -Af
Also neither warnings nor errors are printed into the console-log.
I added a breakpoint to WebAppInitializer.onStartup. This breakpoint was not visited.
Do you have other suggestions what to check or even a solution for this?
-- Solution --
Could it be that simple?
Next day I started the enviroment again.
I added an index.jsp (I didn't configure the web.xml) started the tomcat inside eclipse. It worked.
Afterwards I removed the index.jsp restarted my complete enviroment, redeployed and it is still working.
I think the solution is a simple restart (simple eclipse-caching-problem).
I don't get the point, why adding a file should influence the bootstrap.
Thanks in advice
Mike
It seems to be a simple eclipse-chaching-problem. Here is the reason why (additionally I added this information to the question)
Next day I started the enviroment again. I added an index.jsp (I didn't configure the web.xml) started the tomcat inside eclipse. It worked. Afterwards I removed the index.jsp restarted my complete enviroment, redeployed and it is still working.
I think the solution is a simple restart.

How to set custom metamodel in Acceleo project?

I try to make generator from my custom metamodel. I created it by Obeo Designer - it is ecore metamodel.
So I create new Acceleo Project, choose my metamodel URI (http://org/model/ros) from "Runtime version" and try to run it.
But project can't run and i get exception:
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://org/model/ros' not found. (file:/C:/Users/Jakub%20Kitaj/Downloads/ObeoDesigner-Community-8.1-win32.win32.x86/ObeoDesigner-Community/workspace/TestAcceleo/model/example.ros, 2, 120)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1335)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:78)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:190)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
... 6 more
I think i should set my custom metamodel but how can I do this?
EDIT:
I add this code line:
resourceSet.getPackageRegistry().put("http://org/model/ros", Package.class); but I get same error. http://org/model/ros is my metamodel nsUri and Package.class is instance of element from my metamodel object. :(
What can I do else? :(
What do you need to do for your UML model to be loadable is as below:
EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
The same goes for every metamodel you might need, simply change UMLPackage by XxxPackage according to your metamodel. The Resource Factory is mandatory for UML, but your metamodel might not need one; simply ignore this line if you don't have a custom factory.
You need these two lines to be before the point where your model is loaded. For Acceleo, this is done in the generated Java launcher : simply change the implementation of the registerPackages and registerResourceFactories method to add these needed lines.
Maybe you should compile your metamodel (using emf) first, then export it to a jar file, pasting it on the eclipse plugin folder and restarting your eclipse.
you can right click your .ecore model and click "new".. "other".. and find "Emf Generator Model", (next > next > load > next > finish ..) then you'll get a .genmodel file. with this file opened you click to the root element and click generate all, it will generate a set of projects. then you go to the process of exporting a plugin.. right click to your project and click "export.." > "Plug-in Development" > "Deployable plugins and fragments", go through all the process.. then copy the generated jar files and paste on the plugins folder inside of the eclipse installation folder and restart the eclipse.. as magic you'll have code completion from your metamodel :'D

ClassNotFoundException:scala.PreDef$ issue

I am trying to package a simple executable Jar written in Scala, through Eclipse's Export function.
When attempting to execute the Jar from cmd java -jar test2.jar
I get the following error. Any ideas? Thank you.
Caused by: java.lang.NoClassDefFoundError: scala/Predef$
at Parser.Test(Parser.scala:5)
at Main.main(Main.java:12)
... 5 more
Caused by: java.lang.ClassNotFoundException: scala.Predef$
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 java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
You just need to add the scala library jar to the classpath.
You can do it like this (assuming that the "scala-library.jar" jar is in the current directory) :
java -cp scala-library.jar -jar test2.jar
The documentation for tha java comamnd can be found here: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html
for me i was using jdk 11 and scala library container 2.12.3 and when i changed to jdk 8 it works fine
it is because of jdk11 scala version support
JDK Compatibility
right click on the project , Build path ,configure Build path , edit your jdk to less than 11
You can also package scala library together with your project. See this post
I did removed "Scala Library container" from project.
Next - add needed scala's library (scala-library.jar) to Java BuildPath (in Properties for ) as "Add External JARs..." in my library (not as reference to scala lib). And innclude them all to "Order and Export"
Finally - do Export for project with option "Package required libraries into generate JAR"
and this works fine :)

Jar cannot be opened on different Computer ("Can not find main class")

Today I programmed myself a Little game, which I compiled into a jar through Eclipse - I made sure its a executable jar, or runnable jar or however you want to call it.
I've sent the jar to a friend of mine, but oddly he's not able to open it.
He's always receiving the "Can not find main class" error, which shouldn't pop up since it works perfectly for me. I've already googled but was not able to find a answer.
If you're interested, you can take a look here, if it works for you:
http://www.file-upload.net/download-3939961/WidzDeluxe.jar.html
Now the question I have is kind of obvious I guess, is the error only for him or do you all have the same problem? What's the cause of it?
If people wish, I also upload the code.
You have compiled class files bundled inside this jar with a different (higher) version of Java. Presumably it was Java 1.7 and the friend of yours is trying to open it with Java 1.6.
Here is the stacktrace I received trying to open your executable jar with Java 1.6.0_21:
Exception in thread "main" java.lang.UnsupportedClassVersionError: NewJFrame : Unsupported major.min
or version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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$000(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)
Could not find the main class: NewJFrame. Program will exit.
One possible solution that came to my ming would be to set the compliance level to let's say 6.0 in Java Compiler settings in Eclipse. That should to the trick.
I had this same problem, found I was compiling the program for Java 1.7. I ended up updating Java on all my computers that I was running it on and it worked great.