Cannot establish a connection to h2 database in netbeans - java

i have an embedded h2 database with .mv.db extension. I added the latest h2 driver h2 1.4.189 but i still get this exception when testing connection
Cannot establish a connection to jdbc:h2:E:\xxx using org.h2.Driver (General error: "java.lang.NoClassDefFoundError: com/vividsolutions/jts/io/ParseException" [50000-189])
How can i solve ?

Related

Identifying the right URL to access a database in Java

I'm wondering which would be the right path/url to access the "aliens" database I have in my MySQL Workbench.
As you can see, the connection name is "new connection_1", the user is "root", and the port is "3306".
Then, I think the database name is aliens.
Until now I've tried this in my eclipse IDE for java:
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/aliens","root", "myDatabase");
System.out.println(conn);
The url is now "jdbc:mysql://localhost:3306/aliens","root", "myDatabase", but i receive the following exception:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/aliens
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at EdoardoDatabase.main(MainClass.java:9)
Moreover, I would like to print the "connection", nothing else.
YOu'd need a MySql Connector Jar in your classpath and and a Driver set before initiating the connection.
Class.forName("com.mysql.jdbc.Driver");
You can use maven or download the Driver from Mysql page https://www.mysql.com/products/connector/
your Connection String doesn't look bad at all,
your problem is that Java doesn't know to which driver it should map the mysql driver...
if you are sure you have the Mysql jdbc driver on the ClassPath try
Class.forName("com.mysql.jdbc.Driver")
before you do you getConnection()
this calls the static{} block in the Driver registers the mysql driver for JDBC Connection lookups via the Factory

Recover connection after failover as HikariCP doesn't detect DB DNS change

Environment
Hikari CP Version : 3.4.1
JDK version: 1.8.0_251
Database: Azure SQL
SpringBoot Version: 2.2.2 RELEASE
MS-SQL JDBC Driver version:- 8.4.1-jre8
I am working on a Spring Boot app where I have a requirement for configuring the auto failover of database and we are leveraging Azure Failover Groups. The application is connected to the primary database and when the manual failover of the primary server is done, the application should connect to secondary server which is now the new primary.
Below is my JDBC connection string and Hikari properties:
logging.level.org.springframework.jdbc.core=DEBUG
spring.datasource.url=jdbc:sqlserver://<FailoverGroupname>.database.windows.net:1433;database=<DatabaseName>;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
spring.datasource.username=demo
spring.datasource.password=***
spring.datasource.initialization-mode=always
hibernate.hikari.minimumIdle=0
hibernate.hikari.maxPoolSize=1
hibernate.hikari.autoCommit=false
hibernate.hikari.initializationFailTimeout=3000
hibernate.hikari.connectionTestQuery=SELECT 1
When the application is started, below is the analysis:
Hikari has a valid connection in the pool
Spring JPA Transaction pulls the connection from the pool
Data is getting persisted in database successfully
next, Manual Failover is done
txn.begin(), throws exception
Broken Pipe Write Failed Exception
Connection is closed (SQLServerException: The connection is closed)
Connection remains closed till the application is running
Expectation:
Since pool has come in bad state, the connections after getting closed should be recovered and connect to the new primary database that serves as backup
Does anyone knows how can I re-establish the closed connections to auto reconnect to backup database.

JMeter Couldnt Connect to Phoenix using JDBC Connection

I'm setting up a JMeter Connection to Phoenix using its JDBC Connection Configuration but it wont connect due to some jars and connection problem. I have tried configuring all of the compatible jars and configure the connection but it won't work either.
I've added Phoenix Jar to Classpath in Test Plan Setting.
The JDBC connection setting are as below:
Database Url: jdbc:phoenix://ip:port:/hbase-unsecure/schema_name
Driver Class: org.apache.phoenix.jdbc.PhoenixDriver
After configuring the phoenix database all i want to do is to do some simple query like SELECT * FROM table_name
Using MySQL Connection was successful and it shows me the data inside the database. However using this Phoenix Configuration, it won't even connect to the database and I am getting various error such as
Cannot create JDBC driver of class 'org.apache.phoenix.jdbc.PhoenixDriver' for connect URL
or
Couldn't established connection
or
java.lang.NoClassDefFoungError: Could not initialize class org.apache.phoenix.jdbc.PhoenixDriver
I got it resolved. turns out the driver for phoenix (phoenix-4.7.0.2.6.1.0-129-client) is suitable for JMeter version 2.9.
And in order the phoenix driver to work in JMeter, use phoenix-4.7.0.2.6.4.0-91-client, not phoenix-4.7.0.2.6.1.0-129-client.
and if you have service mapping enabled problem, extract your jar, find hbase-default file, and add another property for service mapping enabled = true.

MySQL connection fails in netbeans while using mysql (Connector/Jdriver)

While trying to connect to my mysql database in netbeans, I get the following error message:
Cannot establish a connection to jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull using com.mysql.jdbc.Driver (Unable to load authentication plugin 'caching_sha2_password'.)
So I can't connect to the database.

How to connect to H2 database using jmeter?

I am using Jmeter with JDBC to connect to h2 database. I have created JDBC connection configuration in the Jmeter Test Plan and given variable name as 'mydb' and my JDBC configuration is as follows:
database connection URL: jdbc:h2:tcp://localhost/d:/h2/sample
Driver class: org.h2.Driver
Username: sa
I have created a JDBC request under the Thread Group and am using the same variable name 'mydb' for the jdbc request. The jmeter throws me an exception.. Cannot create PoolableConnectionFactory (Connection is broken: "unexpected status 16777216" [90067-176])
however, i am able to access the database on my browser.
I am using the below link as a reference for what i am doing:
https://www.coursehero.com/file/p6a7t19/1-Set-up-an-H2-database-Download-an-H2-database-distribution-from/
Any hints on what i am missing??

Categories