I am trying to connect to Orient DB running in Distributed mode and I am getting following error
Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException:
Error on unmarshalling field 'members' in record #-1:-1 with value:
I am using :
OrientDB Version: orientdb-community-1.7-rc and
JDBC Version: OrientDB JDBC Driver 1.7-rc2-SNAPSHOT ALL
Below is my code:
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.orientechnologies.orient.jdbc.OrientJdbcDriver");
Connection connection = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:localhost/VANET", "root", "*****");
}
database "VANET" as per the DB connection String above, is present in OrientDB and I able to access and create classes in VANET using OrientDB Studio.
I have already referred to and tried code as per. But no luck yet.
Please help me resolve this issue.
A little more details about the error I am getting
Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Error on unmarshalling field 'members' in record #-1:-1 with value:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.orientechnologies.common.log.OLogManager.exception(OLogManager.java:162)
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.fromString(ORecordSerializerSchemaAware2CSV.java:543)
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.fromStream(ORecordSerializerStringAbstract.java:80)
at
... * <I removed these lines >* ...
at com.orientechnologies.orient.jdbc.OrientJdbcConnection.<init>(OrientJdbcConnection.java:49)
at com.orientechnologies.orient.jdbc.OrientJdbcDriver.connect(OrientJdbcDriver.java:46)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at org.poc.orientdb.jdbc.OrientJDBC.main(OrientJDBC.java:49)
Caused by: java.lang.NullPointerException
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.getSchemaClass(ORecordSchemaAwareAbstract.java:82)
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.fromString(ORecordSerializerSchemaAware2CSV.java:445)
... 28 more
Related
I have a MySQL database. My friend is trying to access it from a different computer using my public IP.
This is the program he used to test the connection:
public class Main {
public static void main(String args[]) {
String url = "jdbc:mysql://IPadresss:3307/javabase";
String username = "bob";
String password = "bob";
Properties properties = new Properties();
properties.setProperty("bob", "bob");
properties.setProperty("bob", "bob");
properties.setProperty("useSSL", "false");
properties.setProperty("autoReconnect", "true");
System.out.println("Connecting database...");
try (Connection connection = DriverManager.getConnection(url, properties)) {
System.out.println("Database connected!");
} catch (SQLException e) {
throw new IllegalStateException("Cannot connect the database!", e);
}
}
}
This is the error my friend, who is the client, gets:
Connecting database...
Exception in thread "main" java.lang.IllegalStateException: Cannot connect the database!
at SQLConnector.Main.main(Main.java:23)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at SQLConnector.Main.main(Main.java:20)
Caused by: java.sql.SQLException: Access denied for user ''#'Freinds ip' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1710)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104)
... 13 more
Please help me find out what is wrong with my method of connecting to the server, I have remotely given privileges to my friend (user "bob").
So, you have the following error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure java.net.ConnectException: Connection
refused
This could happen for a variety of reasons, and I'm quoting from this answer
If you get a SQLException: Connection refused or Connection timed out
or a MySQL specific CommunicationsException: Communications link
failure, then it means that the DB isn't reachable at all.
This can have one or more of the following causes:
IP address or hostname in JDBC URL is wrong.
Hostname in JDBC URL is not recognized by local DNS server.
Port number is missing or wrong in JDBC URL. [Assuming the one you mentioned is correct]
DB server is down.
DB server doesn't accept TCP/IP connections.
DB server has run out of connections.
Something in between Java and DB is blocking connections, e.g. a firewall or proxy.
To solve the one or the other, follow the following advice:
Verify and test them with ping.
Refresh DNS or use IP address in JDBC URL instead.
Verify it based on my.cnf of MySQL DB.
Start the DB.
Verify if mysqld is started without the --skip-networking option.
Restart the DB and fix your code accordingly that it closes connections in finally.
Disable firewall and/or configure
firewall/proxy to allow/forward the port.
I try to connect to Azure SQL with:
import java.sql.*;
public class ExampleJTDS {
public static void main(String[] args) {
// Setting.
String connectionUrl = "jdbc:jtds:sqlserver://SERVER.database.windows.net:1433/DATABASE;ssl=off";
String user = "USER#SERVER";
String pass = "PASSWORD";
// Declare the JDBC object.
Connection conn = null;
try {
// Establish the connection.
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(connectionUrl, user, pass);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
But I am getting:
java.sql.SQLException: I/O Error: DB server closed connection.
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:632)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:371)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at run.ExampleJTDS.main(ExampleJTDS.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
If I force the encryption by substituting ssl=off with ssl=require, I am getting:
java.sql.SQLException: Network error IOException: Connection reset
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at run.ExampleJTDS.main(ExampleJTDS.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Interestingly, I can connect to the database from the same computer and with the same JDBC driver with SQuirreL SQL (although without SSL - SQuirreL SQL manages to put the credentials into the first TDS packet and Azure accepts that). Hence, the problem should not be in the setting of firewalls.
Metadata:
Server: Azure V12
Driver: jtds-1.3.1
JRE: 1.8.0_72-b15 (from Oracle)
_JAVA_OPTIONS: -Djsse.enableCBCProtection=false
security.provider.1: sun.security.provider.Sun
OS: OS X 10.11.5
SQuirreL SQL: 3.7.1
How can I connect to Azure SQL from Java?
Per my experience, I think the issue was caused by the connection string which is the variable connectionUrl of your code. I have answered your similar question of the SO thread, please see How to connect to Azure SQL with JDBC.
However, using jTDS instead of Microsoft JDBC driver for SQL Server has a little difference, you can refer to a note in the step 3 of the tutorial to know it. As reference, I post the contento of the note here.
Note:
If you are using the JTDS JDBC driver, then you will need to add "ssl=require" to the URL of the connection string and you need to set the following option for the JVM "-Djsse.enableCBCProtection=false". This JVM option disables a fix for a security vulnerability, so make sure you understand what risk is involved before setting this option.
Hope it helps. Any concern, please feel free to let me know.
I'm trying to write a Java program that will connect to a MongoDB database. I already have the IP address, port, userDB, username, and password of the database I'm trying to access.
I have the mongodb-driver-3.0.0.jar file set as a referenced library in Eclipse. I created a MongoDBDriver.java file in the src folder (shown below):
import com.mongodb.MongoClient;
public class MongoDBDriver {
public static void main(String[] args) {
MongoClient client = new MongoClient("10.66.80.152", 27017);
String connectPoint = client.getConnectPoint();
System.out.println(connectPoint);
client.close();
}
}
When I run the script, I get the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError:
com/mongodb/connection/BufferProvider
at MongoDBDriver.main(MongoDBDriver.java:7)
Caused by: java.lang.ClassNotFoundException:
com.mongodb.connection.BufferProvider
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)
... 1 more
So, what am I doing wrong and how can I fix it?
Exception means that you have the class path mismatch.
I create small app that connect java and mongodb and do some CURD operations.
eMongoDB-Java-app
I think it will be better solution to connect database.
MongoClient does not have method getConnectPoint(), class Mongo does.
You can read the official website, it will help you out.mongodb official website java tutorial
I'm a newbie of java programming, and I'm trying to learning.
I have a database mysql and I manage the connection with connection Pool, BoneCP is the library that I use.
The code for create a Pool is this:
BoneCPConfig config = new BoneCPConfig(); // create a new configuration object
config.setJdbcUrl( R.database.url + R.database.dbName ); // set the JDBC url
config.setUsername( R.database.userName ); // set the username
config.setPassword( R.database.password ); // set the password
config.setMinConnectionsPerPartition(2);
config.setMaxConnectionsPerPartition(5);
config.setPartitionCount( 3 );
try{
connectionPool = new BoneCP( config ); // setup the connection pool
}catch( Exception e ){
System.out.println( e );
}
When i need the connection for send query to DB i catch the connection with this line of code:
conn = R.database.connectionPool.getConnection();
I think is all ok at this point and I haven't any errors.
After a min the console say this:
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.BoneCP - Failed to acquire connection to jdbc:mysql://localhost:3306/test_db. Sleeping for 7000 ms. Attempts left: 0
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test_db
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
at com.jolbox.bonecp.BoneCP.obtainInternalConnection(BoneCP.java:269)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:242)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
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:744)
[BoneCP-pool-watch-thread] ERROR com.jolbox.bonecp.CustomThreadFactory - Uncaught Exception in thread BoneCP-pool-watch-thread
java.lang.NoClassDefFoundError: com/jolbox/bonecp/hooks/ConnectionState
at com.jolbox.bonecp.ConnectionHandle.markPossiblyBroken(ConnectionHandle.java:382)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:244)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:115)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
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:744)
This is the strange problem!!
Thank very much!!
No suitable driver found for jdbc:mysql://localhost:3306/test_db
This seems to imply that you don't have a java MySQL JDBC driver on your classpath, have a look at the available connectors for MySQL and make sure the appropriate JAR including this driver is on your classpath.
MySQL Connectors
When I read a file from hdfs by giving it proper path the file is read successfully but when I try to use transform operator of jaql it throws an exception as given below and if I try to execute the code on JAQL shell then an exception is thrown of job.jar but even after adding the jar the exception is still thrown. if anybody knows that somehow JAQL is not configured properly with existing hadoop cluster or the exception is due to some other cause?
My code is:
jaql.setQueryString("read(lines('hdfs://hadoopserver:54310/dbreports/reports.json'," +
"{format: 'org.apache.hadoop.mapred.TextInputFormat',converter: 'com.ibm.jaql.io.hadoop.converter.FromJsonTextConverter'})) -> transform $.store_number;");
System.out.println("jaql running successfully....");
JsonValue jv = jaql.evaluate();
System.out.println("value is "+jv);
when run it throws an exception as:
Exception in thread "Thread-38" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:295)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpMethod
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at sbt.PlayCommands$$anonfun$61$$anonfun$63$$anon$2$$anonfun$loadClass$1.apply(PlayCommands.scala:563)
at sbt.PlayCommands$$anonfun$61$$anonfun$63$$anon$2$$anonfun$loadClass$1.apply(PlayCommands.scala:563)
at scala.Option.map(Option.scala:133)
at sbt.PlayCommands$$anonfun$61$$anonfun$63$$anon$2.loadClass(PlayCommands.scala:563)
... 1 more
java.io.IOException: Job failed!
..........
Do anybody knows what it is that i'm missing?