Skip to content

Ethereum Connection Details

Ashish Shukla edited this page Jul 5, 2018 · 5 revisions

Connection

There are three ways to create a JDBC Connection:

Before creating connection ethereum JDBC Driver class needs to be registered.

Class.forName("com.impetus.eth.jdbc.EthDriver");

Ethereum JDBC supports connection to ethereum network in three ways:

1. RPC

For creating a JDBC connection with RPC, user needs to provide RPC host and port of ethereum node in the connection URL.

Sample URL-

jdbc:blkchn:ethereum://<RPC_HOST>:<RPC_PORT>

Code snippet-

String url ="jdbc:blkchn:ethereum://localhost:8545";
Connection conn = DriverManager.getConnection(url,null);

2. IPC

When a node connects to ethereum network, an IPC file will be generated on the client node.

This IPC file can be used to connect to the ethereum network.

Sample URL-

jdbc:blkchn:ethereum://<IPC_FILE_PATH>

Code snippet-

String url ="jdbc:blkchn:ethereum:///local/path/to/geth.ipc";
Connection conn = DriverManager.getConnection(url, null);

2. INFURA

User needs to provide it's token along with infura end point url as a part of JDBC URL.

Sample URL-

jdbc:blkchn:ethereum://<INFURA_END_POINT_URL>/<USER_TOKEN>

Code snippet-

String url ="jdbc:blkchn:ethereum://ropsten.infura.io/1234";
Connection conn = DriverManager.getConnection(url, null);

Note:-

In case of insert query user needs to create connection with its wallet credentials.

Credentials are keystore file and wallet password.

Sample for setting the property:

Properties prop = new Properties ();
prop.put(DriverConstants.KEYSTORE_PATH, <KEYSTORE_LOCATION>);
prop.put(DriverConstants.KEYSTORE_PASSWORD, <KEYSTORE_PASSWORD>);

Code snippet:

String url =” jdbc:blkchn:ethereum:///local/path/to/geth.ipc”;
Properties prop = new Properties ();
prop.put(DriverConstants.KEYSTORE_PATH, "/local/path/to/ethereum/datadir/keystore/UTC--XXXXXXXXXXXXXXX");
prop.put(DriverConstants.KEYSTORE_PASSWORD, "<password>");
Connection conn = DriverManager.getConnection(url, prop);