I am trying to connect my GWT application to an ldap server using jdbc, but could not make it work so far.
Here is a code sample of my attempt to connect to it:
String ldapConnectString = "jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope";
java.sql.Connection con;
try {
con = DriverManager.getConnection(ldapConnectString,"cn=USERNAME","PASSWORD");
} catch (SQLException e) {
System.out.println("An error has ocurred!!! Connection failed");
e.printStackTrace();
}
The example I used to write this is: http://myvd.sourceforge.net/bridge.html
When I run the application I get following error message:
java.sql.SQLException: No suitable driver found for jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope
I would be thankful for any help
Edit:
The code sample I provided is running on server side accessed by RPC. I included 2 jar files in my lib/ directory downloaded from here: http://sourceforge.net/projects/myvd/files/jdbc%20ldap%20bridge/jdbc%20ldap%20bridge%202.1/jdbc-ldap-2.1.zip/download
You generally need to register the JDBC driver before you can connect to the backend.
Try something like
DriverManager.registerDriver(new com.octetstring.jdbcLdap.sql.JdbcLdapDriver());
before setting up the connection.
More general information on ways of registering drivers.
Related
Did anyone was able to connect to database using Spring boot, R2DBC and encrypted connection
I have a connection string:
jdbc:sqlserver://XXX.XX.XXXX:1433;encrypt=true;trustServerCertificate=true;databaseName=ABC
I am using connection factory builder class and parsed arguments as shown below:
public ConnectionFactory connectionFactory() {
final ConnectionFactoryOptions options = builder()
.option(DRIVER, "sqlserver")
.option(HOST, applicationDatabaseProperties.getHost())
.option(PORT, applicationDatabaseProperties.getPort())
.option(USER, applicationDatabaseProperties.getUsername())
.option(PASSWORD, applicationDatabaseProperties.getPassword())
.option(DATABASE, applicationDatabaseProperties.getDatabase())
.option(SSL, true)
.build()
return ConnectionFactories.get(options);
}
It gives me a runtime SSL error when I am trying to connect
I tried to add an option as shown below - I saw it in the documentation:
.option(Option.valueOf("[trustServerCertificate]","[true]"))
but compiler gives the error(using it from Kotlin code), I decompiled original class io.r2dbc.spi.ConnectionFactoryOptions
and trustServerCertificate is not listed as a constant
Any help would be greatly appreciated
Thanks, Sam
Tried adding the option .option(Option.valueOf("[trustServerCertificate]","[true]")) to the builder,
compiler returns the error
I'm using Azure Cosmos DB 4.0 with MongoDB C# Driver 2.10.4.
Most of the times the queries work fine, but I'm getting intermittent errors like this:
MongoDB.Driver.MongoConnectionException: An exception occurred while sending a message to the server.
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginSend(...
at System.Net.Sockets.NetworkStream.BeginWrite
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.BeginWrite
at System.Net.Security._SslStream.StartWriting
at System.Net.Security._SslStream.ProcessWrite
at System.Net.Security._SslStream.BeginWrite
When that error happens the call takes 10-25 seconds before failing.
I'm building the MongoClient with new MongoClient(MongoClientSettings.FromConnectionString(cnstr)) and I was using the connectionstring with these arguments ?ssl=true&replicaSet=globaldb&retrywrites=false.
I tried with retryWrites=true (as per Azure Support suggestion) but that didn't help.
I tried different settings and that didn't work either (connect=direct, maxIdleTimeMS=30000, serverSelectionTimeout=5000ms, socketTimeout=10000ms).
What's causing those exceptions?
The fix was to set/force TLS 1.2 (based on this Microsoft document):
//return new MongoClient(connectionString);
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.SslSettings = new SslSettings()
{
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12
};
return new MongoClient(settings);
Looks like although my connection string had ssl=true, it wasn't enough to work on some servers (the error is intermittent). The same underlying error can usually be fixed by forcing TLS 1.2 so I assumed that in Mongo it could be the same issue - and it really fixed the problem.
I have mariadb 10.4 running on my system. The db connection is good, i have tested with db workbench with the root password.
On the other hand, I try to connect to it from my Java code, i have the exception below:
java.sql.SQLException: No suitable driver found for jdbc:mariadb://localhost:3306/mydatabase
My java code is as below:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class CountryDAO {
public void list() throws SQLException{
String databaseURL = "jdbc:mariadb://localhost:3306/mydatabase";
String user = "root";
String password = "root";
try
{
Connection connection = DriverManager.getConnection(databaseURL, user, password);
} catch (SQLException ex) {
ex.printStackTrace();
throw ex;
}
}
}
I am calling this code from a servlet.
I am using eclipse and i have added the mariadb-java-client-2.4.2.jar as external jar from build path. It should be working but it doesn't.
UPDATE: Firstly, I have tested my code in a new Eclipse Java project and it works like a charm. Secondly, i have tried to call the same method from a main method of another class, the db connection also work perfectly. So i guess my problem is because i call this connection from a Servlet. I don't know why it does so but i am kind of stuck. Do you have any suggestions?
You have to load the driver first.
Class.forName("org.mariadb.jdbc.Driver");
I have been trying to load the SQL script schema into MySQL DB using Vertx.
Though, i am able to load or update any single DB command but unable to load complete schema in one go.
The second challenge faced is that, this might be blocking code for Vertx application. If that is the case, how can it be avoided?
Here is the code snippet i have been trying to execute:
jdbcClient.getConnection(resConn -> {
if(resConn.succeeded()) {
SQLConnection connection = resConn.result();
connection.execute("<Trying to load the SQL Script schema>", resSchema -> {
connection.close();
if(resSchema.succeeded()) {
async.complete();
} else {
testContext.fail("Failed to load bootstrap schema: " + resSchema.cause().getMessage());
}
});
} else {
testContext.fail("Failed to obtain DB connection for schema write");
}
});
The MySQL JDBC driver does not allow to execute a file as a SQL script. You must parse the script and execute individual commands one by one.
I want to connect to a database in Jdeveloper 11g but there seems to be a problem with my driver for SQL Server 2000. I have downloaded the appropriate driver (Sqljdbc4.jar) but I do not know how to include or use it in my code.
import java.sql.*;
class TestConnection
{
public static void main (String[] args)
{
try
{
// Step 1: Load the JDBC ODBC driver
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Step 2: Establish the connection to the database
String url = "jdbc:sqlserver://10.1.73.180\\SQL2000;" +
"databaseName=reportgen;user=sa;password=*****;";
Connection conn = DriverManager.getConnection(url);
System.out.println("Connected.");
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
and this shows when I try to run my TestConnection.java class:
Got an exception!
com.microsoft.sqlserver.jdbc.SQLServerDriver
Process exited with exit code 0.
Project properties->libraries and class path->add JAR.
You might also need to add this to the embedded WebLogic instance.
You can also use tools->manage libraries to add a library and then add that library to your project.