Error when connecting H2 with symmetricDS using jdbc - database

Im trying to create a database connection between H2 and SymmetricDS in a virtual machine. Following this toturial (H2-Installation), Im able to install H2 and create store001 H2 database using H2-browser. However, when I connect to SymmetricDS, it throws some error on the connection.
Symmetric config:
db.driver=org.h2.Driver
db.url=jdbc:h2:~/store001;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
H2 config (in h2.sh):
java -cp "$dir/h2-1.4.200.jar:$H2DRIVERS:$CLASSPATH" org.h2.tools.Server -web -webAllowOthers -ifNotExists "$#"
H2 Browser (managed to create store-001):
Error when running symmetricDS using H2 jdbc connection:
Caused by: org.h2.jdbc.JdbcSQLException: IO Exception: "/root/store001 outside /opt/symmetric-server-3.12.10/db/h2" [90028-176]
These are steps I tried to solve this issue:
Adding -Dh2.baseDir=/ in h2.sh. Following this solution -> solution-example
But got this error when running H2:
Exception in thread "main" org.h2.jdbc.JdbcSQLFeatureNotSupportedException: Feature not supported: "-Dh2.baseDir=/" [50100-200]
Change H2 Browser from Embedded to Server. But got this error in browser:
Connection is broken: "java.net.ConnectException: Connection refused (Connection refused): localhost" [90067-200] 90067/90067 (Help)
What should i do to solve this issue?

SymmetricDS is using version 1.3.176 for H2.
Use the 1.3.176 H2 jar file from the SymmetricDS installation:
java -cp /opt/symmetric-ds/web/WEB-INF/lib/h2-1.3.176.jar::$H2DRIVERS:$CLASSPATH" org.h2.tools.Server -web -webAllowOthers -ifNotExists "$#"
You can specify the H2 URL to be as follows when you create the file:
jdbc:h2:/opt/symmetric-ds/tmp/h2/store001

Related

Getting an error message from a sql server driver in my symfony project

I have tried to install the ODBC driver 18 for SQL Server in my symfony project. I am getting the following error messages. I wanted to ask if anyone could knows the solution for these.
An exception occurred in the driver: SQLSTATE[08001]: [Microsoft][ODBC
Driver 18 for SQL Server]SSL Provider: [error:16000069:STORE
routines::unregistered scheme:scheme=file][error:80000002:system
library::No such file or direc tory:calling
stat(/usr/local/etc/openssl#3/certs)][error:16000069:STORE
routines::unregistered scheme:scheme=file]
Environment details:
symfony version: 5.4.16
php8.1
Homebrew 3.6.16
apache 2.4.54
#AlwaysLearning's answer did help me.From the article linked, I checked the openssl#3 folder and I did see there was a cert.pem file. I then created a certs directory and copied the cert.pem file into that directory. That got of rid of my error message.
I did encounter an additional issue where I needed to add TrustServerCertificate parameter to the end of my connection string that is used to connect to the SQL server.
;TrustServerCertificate=1

liquibase.exception.DatabaseException: Connection could not be created with driver com.microsoft.sqlserver.jdbc.SQLServerDriver

I am developing my application in SpringBoot which uses liquibase to update my ms-sql database.
This worked fine till now, but now I am trying to update everything to the latest version:
I changed java from 15 to 17.
I also updated liquibase-maven-plugin to 4.5.0.
mssql-jdbc dependency for liquibase is: mssql-jdbc:9.4.0.jre16
The new mssql-jdbc_auth-9.4.0.x64.dll file is moved to this folder:
c:\apps\Java\x64\jdk-17\bin\ (this is my java location).
My IntelliJ is set to use java 17 (JAVA_HOME is also configured to
the 17 path)
the version of Microsoft SQL Server Express (64-bit): 11.0.2100.60
So I think I did everything, but still, when I try to run my maven, I get the following error:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:4.5.0:update (myDatabase) on project my-project:
[ERROR] Error setting up or running Liquibase:
[ERROR] liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:sqlserver://localhost:1433;databaseName=My_Database;integratedSecurity=true with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]"

SQL Server through JDBC in PySpark

os.environ.get("PYSPARK_SUBMIT_ARGS", "--master yarn-client --conf spark.yarn.executor.memoryOverhead=6144 \
--executor-memory 1G –jars /mssql/jre8/sqljdbc42.jar --driver-class-path /mssql/jre8/sqljdbc42.jar")
source_df = sqlContext.read.format('jdbc').options(
url='dbc:sqlserver://xxxx.xxxxx.com',
database = "mydbname",
dbtable=mytable,
user=username,
password=pwd,
driver='com.microsoft.jdbc.sqlserver.SQLServerDriver'
).load()
I am trying to load SQL Server Table using Spark Context.
But running into the following error.
Py4JJavaError: An error occurred while calling o59.load.
: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
I have the jar file in the location. Is that the correct jar file?
Is there a problem with the code.
Not sure what is the problem.
Scala error
scala> classOf[com.microsoft.sqlserver.jdbc.SQLServerDriver]
<console>:27: error: object sqlserver is not a member of package com.microsoft
classOf[com.microsoft.sqlserver.jdbc.SQLServerDriver]
scala> classOf[com.microsoft.jdbc.sqlserver.SQLServerDriver]
<console>:27: error: object jdbc is not a member of package com.microsoft
classOf[com.microsoft.jdbc.sqlserver.SQLServerDriver]
The configuration is similar to Spark-Oracle configuration.
Here is my Spark-sqlserver configurations:
from pyspark.sql import SparkSession
spark = SparkSession\
.builder\
.master('local[*]')\
.appName('Connection-Test')\
.config('spark.driver.extraClassPath', '/your/jar/folder/sqljdbc42.jar')\
.config('spark.executor.extraClassPath', '/your/jar/folder/sqljdbc42.jar')\
.getOrCreate()
sqlsUrl = 'jdbc:sqlserver://your.sql.server.ip:1433;database=YourSQLDB'
qryStr = """ (
SELECT *
FROM yourtable
) t """
spark.read.format('jdbc')\
.option('url',sqlsUrl)\
.option('driver', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')\
.option('dbtable', qryStr )\
.option("user", "yourID") \
.option("password", "yourPasswd") \
.load().show()
Set the location of the jar file you downloaded => "/your/jar/folder/sqljdbc42.jar". The jar file can be downloaded from: https://www.microsoft.com/en-us/download/details.aspx?id=54671 (*google sqljdbc42.jar if the link does not work)
Set the correct jdbc url => 'jdbc:sqlserver://your.sql.server.ip:1433;database=YourSQLDB' (change the port number if you have a different setting)
Set the correct driver name => .option('driver', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
Enjoy
I installed Spark in Windows and got the same error while connecting to SQL Server following the steps described here https://docs.azuredatabricks.net/spark/latest/data-sources/sql-databases.html#python-example. I solved this like below -
1) Download SQL Server JDBC driver from here https://www.microsoft.com/en-us/download/details.aspx?id=11774.
2) Unzip as "Microsoft JDBC Driver 6.0 for SQL Server"
3) Find the JDBC jar file (like sqljdbc42.jar) in folder "Microsoft JDBC Driver 6.0 for SQL Server".
4) Copy the jar file (like sqljdbc42.jar) to "jars" folder under Spark home folder. In my case, I copied it and pasted it to "D:\spark-2.3.1-bin-hadoop2.6\jars"
5) restart pyspark
In this way I solved this for Windows server.

Configuring a Postgresql connection with Play 2 and Slick-Play

I'm learning how to build an application using Scala and the Play 2 Framemork. I`ve created a new project using the activator tool, based on "play-scala-intro" current template.
The template have a sample app using the Play-Slick 1.0 for managing dependencies and is configured with a H2 DB, that worked without problems.
When I tried to change to a Postgres DB, I'm running in trouble. I get an error 500, telling me:
"Cannot connect to database [default]".
In the stack trace, the exception is:
"Configured Slick driver org.postgresql.Driver is not an instance of
requested profile slick.profile.BasicProfile"
So... What I already did:
I added to my build.sbt file the dependency:
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
In my configuration file (application.conf), the DB connection is configured as:
slick.dbs.default.driver=org.postgresql.Driver
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres" slick.dbs.default.db.password=""
PS: I've tried with slick.dbs.default.driver="org.postgresql.Driver" too...
PS2: My db password is empty. I'm connecting with PgAdmin without problems
slick.dbs.default.driver must be a slick driver, not a JDBC driver. Your db config should look something like this:
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres"
slick.dbs.default.db.password=""

Unable to connect to Database using MySQLdb in Robotframework

Using Robotframework 2.6.3 and the python database library, I want to connect to MySql Database.
I have downloaded the DatabaseLibrary and MySQLdb however when I try to connect using:
Library DatabaseLibrary
DatabaseLibrary.Connect To Database MySQLdb cts1 root password 172.16.7.20
I get the following error, when I run this using pybot:
OperationalError: (2003, "Can't connect to MySQL server on '172.16.7.20' (10061)")
Note:
cts1 - is the DB name and 172.16.7.20 - is the IP address of DB.
This works when I use mysql under the command prompt. Why would it not be able to connect?
The issue was I did not provide any PORT into robotframework and it does not correctly use the default port of 3306. Once I put the port in, it worked.

Resources