I've used JDBC without any problems many times before, but for some reason on a new server I have it isn't working. The code compiles and runs fine on my main machine, and all the libraries (including the JDBC) should be compiled into a single JAR that I run.
Basic code:
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.err.println("Cannot load driver...");
e.printStackTrace();
}
try
{
connection = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=dbuser&password=dbpass");
statement = connection.createStatement();
}
catch (SQLException e)
{
System.err.println("Cannot connect to database...");
e.printStackTrace();
}
The error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.mysql.jdbc.Util.stackTraceToString(Util.java:355)
at com.mysql.jdbc.Util.<clinit>(Util.java:120)
at com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:764)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:222)
at com.test.Server.<init>(Server.java:78)
at com.test.Server.main(Server.java:49)
Caused by: java.lang.RuntimeException: Can't load resource bundle due to underlying exception java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_GB
at com.mysql.jdbc.Messages.<clinit>(Messages.java:61)
... 8 more
Caused by: java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_GB
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1539)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1278)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:733)
at com.mysql.jdbc.Messages.<clinit>(Messages.java:59)
... 8 more
I've never had this kind of error before, and Google is not being helpful at all. I've checked the database credentials, port number, etc. Would appreciate any help on solving it!
I encountered the same problem when I used Tomcat.
Here is my solution: add the JAR package mysql-connector-java:<version> to the lib package in Tomcat's (or your server's) installation path.
Replace..
connection = DriverManager.getConnection("jdbc:mysql://localhost/dbname?user=dbuser&password=dbpass");
with ..bcoz default port is 3306 for mysql.If changed give that
DriverManager.getConnection("jdbc:mysql://localhost:3306/minebench", "username", "password");
and add "mysql-connector-java-5.1.0-bin.jar".
then try it .
Related
How can I connect to Microsoft SQL Server from my java code?
Code:
public class insert {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://LENOVO-PC\\SQLEXPRESS;DatabaseName=dbtest";
Connection connection = DriverManager.getConnection(url , "sa" , "Aa123456");
Statement st = connection.createStatement();
st.executeUpdate("INSERT INTO [dbo].[table] VALUES ('come')");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(2);
}
}
}
Error:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
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 insert.main(insert.java:12)
Microsoft SQL Server name is: LENOVO-PC\SQLEXPRESS
and sqljdbc.jar is already added to the referenced libraries.
The class name com.microsoft.jdbc.sqlserver.SQLServerDriver you're trying to load is from a very old version of the Microsoft SQL Server 2000 version of the driver. Around 2005, Microsoft changed this to com.microsoft.sqlserver.jdbc.SQLServerDriver (notice the switch in order between jdbc and sqlserver). At that time, they also changed the driver URL prefix from jdbc:microsoft:sqlserver: to jdbc:sqlserver:.
In other words, you need to:
Use Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver") (optional, driver will be loaded automatically)
Change your URL to jdbc:sqlserver://LENOVO-PC\\SQLEXPRESS;databaseName=dbtest (note the prefix change and DatabaseName -> databaseName. See also Building the Connection URL.
With recent JDBC drivers, it is not necessary to explicitly load the driver class in simple Java applications, so instead of step 1, you could also remove the Class.forName line.
Also make sure you are using a recent version of the driver, see the mssql-jdbc project on GitHub (latest stable version at time of writing is 7.0.0).
Correct the driver class name:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
how can i fix this exception i can't get acces to the database on cloud google with app engine plug-in
im using the appengine 1.9.22
this is my print stack:
juin 11, 2016 7:41:30 PM
com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver openConnection
AVERTISSEMENT: openConnection
java.sql.SQLException: 404 OK
Not Found
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.newOpenConnectionIOException(RpcGoogleApi.java:168)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:102)
at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver.openConnection(LocalRdbmsServiceRemoteDriver.java:206)
at com.google.appengine.api.rdbms.dev.LocalRdbmsService.openConnection(LocalRdbmsService.java:121)
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:606)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:521)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:475)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:452)
at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:493)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:490)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.api.client.http.HttpResponseException: 404 OK
Not Found
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1061)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.execImpl(RpcGoogleApi.java:326)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.exec(RpcGoogleApi.java:308)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:99)
... 16 more
I had the same problem last Friday.
I didn't found any documentation to support this claim but, by reading current google's documentation and guides on how to connect to cloud sql with java, it appears that rdbms.dev.LocalRdbmsServiceRemoteDriver is deprecated.
I would recommend you to upgrade your code to use com.mysql.jdbc.GoogleDriver in production and MySQL Connector/J in development.
In development, you could use your own mysql database running on localhost or remotely. If you want to use a db from Google Cloud SQL you could configure your instance of cloud SQL to allow external access from your network and then create a connection like any other mysql server.
You could create create a db connection for each runtime environment:
protected Connection getConnection() throws SQLException{
Connection c = null;
String url = null;
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
try {
Class.forName("com.mysql.jdbc.GoogleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Driver unavailable.");
}
url = System.getProperty("ae-cloudsql.cloudsql-database-url.prod");
}else{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
System.out.println("Driver unavailable.");
}
url = System.getProperty("ae-cloudsql.cloudsql-database-url.dev");
}
c = DriverManager.getConnection(url);
c.setAutoCommit(false);
return c;
}
Extracted from the documentation:
-Creating a New Web App with Cloud SQL Support
-Using Google Cloud SQL
i'm using the second generation of cloud sql to connect to my db when i run on local :)
I've just upgraded to El Capitan and I'm running into problems starting a custom JavaFX2 application running under JDK1.7.0u79 (the latest available from Oracle).
When starting the app, I'm getting this Exception:
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at javafx.scene.control.Control.loadClass(Control.java:115)
at javafx.scene.control.Control.loadSkinClass(Control.java:1021)
at javafx.scene.control.Control.access$500(Control.java:70)
at javafx.scene.control.Control$12.invalidated(Control.java:972)
at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:127)
at javafx.beans.property.StringPropertyBase.set(StringPropertyBase.java:161)
at com.sun.javafx.css.StyleableStringProperty.set(StyleableStringProperty.java:71)
at javafx.scene.control.Control$12.set(Control.java:964)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:59)
at com.sun.javafx.css.StyleableStringProperty.applyStyle(StyleableStringProperty.java:31)
at com.sun.javafx.css.StyleableProperty.set(StyleableProperty.java:70)
at com.sun.javafx.css.StyleHelper.transitionToState(StyleHelper.java:900)
at javafx.scene.Node.impl_processCSS(Node.java:7418)
at javafx.scene.Parent.impl_processCSS(Parent.java:1146)
at javafx.scene.control.Control.impl_processCSS(Control.java:1154)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Parent.impl_processCSS(Parent.java:1153)
at javafx.scene.Node.processCSS(Node.java:7386)
at javafx.scene.Scene.doCSSPass(Scene.java:454)
at javafx.scene.Scene.preferredSize(Scene.java:1468)
at javafx.scene.Scene.impl_preferredSize(Scene.java:1535)
at javafx.stage.Window$9.invalidated(Window.java:717)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
at javafx.stage.Window.setShowing(Window.java:781)
at javafx.stage.Window.show(Window.java:796)
at javafx.stage.Stage.show(Stage.java:233)
at au.com.religaresecurities.trademax.client.Start.start(Start.java:131)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
Caused by: java.lang.NullPointerException
at com.sun.t2k.MacFontFinder.initPSFontNameToPathMap(MacFontFinder.java:339)
at com.sun.t2k.MacFontFinder.getFontNamesOfFontFamily(MacFontFinder.java:390)
at com.sun.t2k.T2KFontFactory.getFontResource(T2KFontFactory.java:233)
at com.sun.t2k.LogicalFont.getSlot0Resource(LogicalFont.java:184)
at com.sun.t2k.LogicalFont.getSlotResource(LogicalFont.java:228)
at com.sun.t2k.CompositeStrike.getStrikeSlot(CompositeStrike.java:86)
at com.sun.t2k.CompositeStrike.getMetrics(CompositeStrike.java:132)
at com.sun.javafx.font.PrismFontUtils.getFontMetrics(PrismFontUtils.java:31)
at com.sun.javafx.font.PrismFontLoader.getFontMetrics(PrismFontLoader.java:466)
at javafx.scene.text.Text.<init>(Text.java:153)
at javafx.scene.text.Text.<init>(Text.java:162)
at com.sun.javafx.scene.control.skin.ProgressIndicatorSkin.<clinit>(ProgressIndicatorSkin.java:78)
... 37 more
I can't just migrate the app to Java 8, so any help is much appreciated.
Update
I've been able to get the app running again by adding this to the start of my main method. Any better solutions out there?
try {
Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
psNameToPathMap.setAccessible(true);
psNameToPathMap.set(null, new HashMap<String, String>());
} catch (Exception e) {
// ignore
}
After more than a week with that in an extensive enterprise application, I haven't noticed any problems in the UI.
For the lack of a better solution, I'm accepting my update above as answer. Maybe it helps someone...
I've been able to get the app running again by adding this to the start of my main method.
try {
Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
psNameToPathMap.setAccessible(true);
psNameToPathMap.set(null, new HashMap<String, String>());
} catch (Exception e) {
// ignore
}
This isn't a direct answer, however I thought it important to pass on that this bug has been identified and fixed in an upcoming Java release. See https://bugs.openjdk.java.net/browse/JDK-8143907
I had the same problem. I changed the Text to a Label. I'm not sure it's possible in your case.
I am having my java program for Neo4j with the Neo4j version as 2.3.0m1 .The jar files i was using for the connect was neo4j-desktop-2.3.0-M01.jar . Everything works fine. Now i want to load databases from 2.3.0-m3 version which is not opening in the current version. I am not able to find any jar files for this new version either .
This is my java code
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
public class Testing {
public static void main(String args[])
{
System.out.println("hai");
GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
GraphDatabaseService db= dbFactory.newEmbeddedDatabase("D:\\graph.db");
try (Transaction tx = db.beginTx()) {
System.out.println("began transaction");
tx.success();
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Done successfully");
}
}
This is the error i am getting if i try to open a higher version db (from 2.3.0-M3)
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, D:\data2\graph.db
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:314)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:59)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:107)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:94)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:176)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:66)
at Testing.main(Testing.java:19)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.state.DataSourceManager#258bb6ba' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:499)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:108)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:309)
... 6 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.NeoStoreDataSource#f1cb476' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:499)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:108)
at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:117)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:493)
... 8 more
Caused by: org.neo4j.kernel.impl.storemigration.StoreUpgrader$UpgradingStoreVersionNotFoundException: 'neostore.nodestore.db' does not contain a store version, please ensure that the original database was shut down in a clean state.
at org.neo4j.kernel.impl.storemigration.UpgradableDatabase.checkUpgradeable(UpgradableDatabase.java:86)
at org.neo4j.kernel.impl.storemigration.StoreMigrator.needsMigration(StoreMigrator.java:158)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.getParticipantsEagerToMigrate(StoreUpgrader.java:259)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.migrateIfNeeded(StoreUpgrader.java:134)
at org.neo4j.kernel.NeoStoreDataSource.upgradeStore(NeoStoreDataSource.java:532)
at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:434)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:493)
... 11 more
Also i am trying to download the enterprise version zip(2.3.0-M1) for windows from neo4j web site because i have the import-graphml feature in 2.3.0-M3 for which i want to move up to 2.3.0-M3.But the link provided in neo4j site is not downloading it completly.
http://neo4j.com/artifact.php?name=neo4j-enterprise-2.3.0-M01-windows.zip
Is there somewhere else this can be downloaded from
If you are doing upgrade of Neo4j you also need to upgrade database version.
neo4j.properties
# Enable this to be able to upgrade a store from an older version.
allow_store_upgrade=true
I am not able to connect to HBase through Apache phoenix driver.
Env info:
hadoop-2.6.0.
hbase-0.98.9-hadoop2.
phoenix-4.1.0-server-hadoop2(Kept on all region servers).
phoenix-4.1.0-client-hadoop2(Using this jar to create a jdbc connection).
Java Client side , I am getting exception
Caused by: org.apache.phoenix.exception.PhoenixIOException: org.apache.hadoop.hbase.DoNotRetryIOException: java.io.IOException: Class org.apache.phoenix.coprocessor.MetaDataRegionObserver cannot be loaded
at ...
Caused by: java.io.IOException: Class org.apache.phoenix.coprocessor.MetaDataRegionObserver cannot be loaded
at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.testTableCoprocessorAttrs...
At HBase Master node logs I am getting this error:
2015-02-02 12:48:11,550 DEBUG [FifoRpcScheduler.handler1-thread-14] util.FSTableDescriptors: Exception during readTableDecriptor. Current table name = SYSTEM.CATALOG
org.apache.hadoop.hbase.TableInfoMissingException: No table descriptor file under hdfs://HadoopNode:9000/home/hduser/Data/hbase/data/default/SYSTEM.CATALOG
Code which I am using to create phoenix connection:
String zkQuorum = "HbaseMasterNode:2222";
try
{
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
String connectionURL = "jdbc:phoenix:" + zkQuorum;
Connection connection = DriverManager.getConnection(connectionURL);
System.out.println(connection);
}
catch (Exception e)
{
throw new IllegalArgumentException("Create phoenix connection(" + zkQuorum + ") throw exception", e);
}
With the help of Basic Hbase java APIs I am able to connect but this issue I am facing only If I try to use Phoenix driver for HBase.