Sqlite Connect with ruby java bridge - java

I am trying to connect to an sqlite database using Rjb and the JDBC driver from https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage
I cannot work out how to call the following Java using Rjb:
Class.forName("org.sqlite.JDBC")
Has anyone connected to sqlite using Rjb with success?
The RJB code I have so far is as follows and is throwing the exception 'java.sql.SQLException: No suitable driver found for jdbc:sqlite:/Users/obrientimothya/Dropbox/development/vle/db/development.sqlite3'
Connection = Rjb::import 'java.sql.Connection'
DriverManager = Rjb::import 'java.sql.DriverManager'
SQLException = Rjb::import 'java.sql.SQLException'
DriverManager.registerDriver(Rjb::import('org.sqlite.JDBC'))
connection = DriverManager.getConnection("jdbc:sqlite:/Users/obrientimothya/development.sqlite3")

I ended up solving this by adding the system property jdbc.drivers when loading the JVM...
Rjb::load( classpath, ['-Djdbc.drivers=org.sqlite.JDBC','-Xms128M', '-Xmx256M'] )
This tells java.sql.DriverManager to load the sqlite jdbc driver class itself, eliminating the need for a Class.forName() call.

Related

How to set a MS Access DB (.mdb) in JasperSoft Studio (Eclipse)?

I have a .mdb database and I'm trying to design a report using JasperSoft Studio 6.3.0 (Eclipse plug-in).
In my Java Application I have used the UCanAccess JDBC Driver to build the connection as JDBC-ODBC Bridge is no longer supported in Java 8.
When creating the Data Adapter, I chose "Database JDBC Connection", and then, as UCanAccess is not in the default list of Drivers, I added the .jar file with the UCanAccess Driver.
Screenshot from the Classpath:
Then, I wrote the Driver Class in JDBC Driver (note: the standard action is to choose one of the drivers in the combobox, but as I had to add it manually, I read somewhere in the Internet that I must write it by myself).
Screenshot from the Driver setting:
When I test the connection, it will stay loading forever and will never end.
NOTE: the database has no user/pass. I successfully connected the database to my Java application (using the UCanAccess Driver); my problem is with the connection to the report.
What can I do? Any suggestions? Thanks!
I managed to solve my question by myself. I also had to add the four .jar in UCanAccess-x.x.x-bin>>lib to the Classpath (commons-lang, commons-logging, hsqldb, jackcess)

Connection to SQLServer2012 with JTDS driver and Windows authentication

I am trying to connect to Microsoft SQLServer 2012 through Java. I have tried using the Microsoft supplied jdbc driver, as well as the jtds driver.
However, whenever i try to load either of the drivers, I get a "No suitable driver found" exception.
The connection URL i have is:
jdbc:jtds:sqlserver://localhost:1433/mineDB;instance=SQLServer2012;integratedSecurity=true;USENTLMV2=true
The driver class name:
net.sourceforge.jtds.jdbc.Driver
I have loaded the jtds.1.3.1.jar file into my classpath system variable, and when trying to use the windows jdbc driver i did the same
EDIT:
Forgot to mention. the driver is called using Class.forName().
Everything is being done on one machine at the moment, and once it is all working i'm going to see if i can get an external database connection working

Exception while connecting to DB2 in java using JDBC

I am trying to connect to a db2 database in Java. Below the driver and the connection string and the driver details i am giving
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
But I am getting the below exception
"COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0615E Error receiving from socket, server is not responding. SQLSTATE=08S01"
I also tried changing the connection string to
String url="jdbc:db2:hostname:portnumber/databasename";
Still it is resulting the same exception above while trying to get the Connection.
And i have tried the below option also using JDBC app driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
DB2DataSource db2ds = new DB2DataSource();
db2ds.setServerName("hostname");
db2ds.setPortNumber(portnumber);
db2ds.setDatabaseName("databasename");
db2ds.setUser("username");
db2ds.setPassword("password");
sourceConnection=db2ds.getConnection();
For the above two connection I used the jar "db2java.jar"
And i have tried using the JCC driver:
Class.forName("com.ibm.db2.jcc.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
For this connection i have added the below jars
1)db2jcc.jar
2)db2jcc_license_cu.jar
This time around I am getting the below error,
"com.ibm.db2.jcc.am.go: [jcc][t4][201][11237][3.57.82] Connection authorization failure occurred.
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000"
I tried to connect to the same db2 source using "Quest for DB2" tool and the connection was successful.
Am i missing something in the code and is it a problem with DB2 drivers or connection string?
Can someone please guide me.
Thanks in advance.
Cause:
If the DB2® instance where InfoSphere Optim Performance Manager is running has the authentication configuration parameter set to DATA_ENCRYPT, you cannot log in to the web console.
Resolving the problem:
Do the following steps:
On the DB2 instance where Optim Performance Manager is running, set the authentication configuration parameter to SERVER by issuing the following command:
db2 update dbm cfg using authentication server
Restart the DB2 instance and InfoSphere Optim Performance Manager.
For more details visit here.
Your first two attempts were not supposed to work. You're using the JCC driver URL format, so it wouldn't be valid for either "net" or "app" drivers, which are deprecated anyway.
Use the JCC driver (com.ibm.db2.jcc.DB2Driver) and the URL format of "jdbc:db2://hostname:portnumber/databasename" and see this technote for the solution to the "Security mechanism not supported" problem. In short, you need to use a supported JDK.

Connection from a Java program to a SQL Developer database

I would like to access to a Oracle database (SQL Developer) from a Java program. I never used JDBC before.
Here is what i wrote:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:host_name:port:database_name";
Connection con = DriverManager.getConnection(url, login, passwd);
I got an error:
[Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
Host name, port, DB name and logins are good.
Is this driver OK to communicate with SQL Developer ?
I don't know what to do,
thanks for helping !
Try this
Class.forName ("oracle.jdbc.driver.OracleDriver");
for Oracle you can use ojdbc
Class.forName("oracle.jdbc.driver.OracleDriver");
for SQL Server u can use jtds
Class.forName("net.sourceforge.jtds.jdbc.Driver");
The JDBC driver sun.jdbc.odbc.JdbcOdbcDriver is bridge driver that wraps an ODBC driver as described here.
SQL Developer is an Oracle tool that acts as an IDE against the Oracle database.
To connect Java to an Oracle database you should obtain the Oracle JDBC driver and ensure the jar is on your classpath (as described in the documentation for java.sql.DriverManager, forcing the class to be loaded is no longer necessary).
The important bit is the connection string, which in its simplest form for Oracle should follow the structure:
jdbc:oracle:thin:#//host:port/service
Where:
host: the hostname of the machine running Oracle
port: the port that Oracle is listening for connections on
service: the database instance to connect to
The full docs are here.

Error while connecting to Oracle DSN using Java

I need to develop an application that connects to various DSN's using the Microsoft ODBC drivers. I have developed the application in Eclipse and it seems to work properly. The connection succeeds and I am able to view table data.
However when I export the project to a runnable jar file (using Eclipse) the functionality fails for Oracle. It is unable to establish connectivity with the Oracle connection string. It still works for SQL server but fails in case of Oracle. I'm unable to figure out the cause as the same ODBC drivers are being used for both Oracle and SQL-Server. More mystifying is that it runs properly on Eclipse. Since im using the ODBC drivers I don't believe the problem is because of an external jar file.
The driver is sun.jdbc.odbc.JdbcOdbcDriver and connection string is like jdbc:odbc:oratest;user=fell;password=pass.
I'm getting the following exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
Can you please help me figure what the problem might be?
Thanks in advance,
Fell
Create a System DSN.
java.sql.Connection cn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=java.sql.DriverManager.getConnection("jdbc:odbc:dsn_name","user","pass");
Check the classpath in the eclipse project

Categories

Resources