Reputation: 887
I am trying to establish a connection with Salesforce via JDBC driver which I got from https://github.com/ascendix/salesforce-jdbc
I have set up this driver in SQLWorkbench tool. The connection is successful. But when I execute any query like SELECT Id from Account it fails with error
Detail Log:
2019-08-14 00:03:14 INFO Creating new connection for [{Default group}/SFJDBC -- https://github.com/ascendix/salesforce-jdbc] for driver=com.ascendix.jdbc.salesforce.ForceDriver and URL=[jdbc:ascendix:salesforce://https://login.salesforce.com/services/Soap/u/37.0;user=xyz;password=xyz]
2019-08-14 00:03:16 INFO WbWin-1 TAB-1: Using DBID=ascendix_jdbc_driver_for_salesforce
2019-08-14 00:03:16 INFO WbWin-1 TAB-1: Using identifier quote character: "
2019-08-14 00:03:16 INFO WbWin-1 TAB-1: Using search string escape character:
2019-08-14 00:03:16 WARN WbWin-1 TAB-1: The driver did not return any table types using getTableTypes(). Using default values: [TABLE, VIEW]
2019-08-14 00:03:16 INFO WbWin-1 TAB-1: Using catalog separator: .
2019-08-14 00:03:16 INFO Connected to: [Ascendix JDBC driver for Salesforce], Database version info: [39], Database version number: [39.0], Driver version: [1.1], JDBC version: [4.0], ID: [WbWin-1 TAB-1]
2019-08-14 00:03:19 WARN The JDBC driver does not support the setMaxRows() function! (null)
2019-08-14 00:03:19 ERROR Error executing:
SELECT Id from Account
java.lang.NullPointerException
java.lang.NullPointerException
at workbench.sql.commands.SelectCommand.execute(SelectCommand.java:131)
at workbench.sql.StatementRunner.runStatement(StatementRunner.java:552)
at workbench.gui.sql.SqlPanel.displayResult(SqlPanel.java:3468)
at workbench.gui.sql.SqlPanel.runStatement(SqlPanel.java:2199)
at workbench.gui.sql.SqlPanel$16.run(SqlPanel.java:2137)
I checked the Database Explorer-> Objects tab has a list of all objects (Account, Contact, etc.) But when I clicked on Data tab to check the data there also got the same above error.
So I even tried to write JDBC code in eclipse there also connection was successful but on executing code I got below error
Connected to Salesforce.
com.ascendix.jdbc.salesforce.ForceConnection createStatement
INFO: createStatement
java.lang.NullPointerException
at SFJDBC.main(SFJDBC.java:77)
Code for Reference:
try
{
final String UserName = "user";
final String Password = "password";
String dbURL = "jdbc:ascendix:salesforce://login.salesforce.com";
String dbUsername = "xyz";
String dbPassword = "xyz";
java.util.Properties connProperties = new java.util.Properties();
connProperties.put(UserName, dbUsername);
connProperties.put(Password, dbPassword);
Class.forName("com.ascendix.jdbc.salesforce.ForceDriver");
Properties connectionProps = new Properties();
connectionProps.put(UserName,dbUsername);
connectionProps.put(Password,dbPassword);
Connection connection = DriverManager.getConnection(dbURL, connectionProps);
System.out.println(connection.toString());
if(!connection.isClosed())
{
System.out.println("Connected to Salesforce.");
Statement stmt = null;
ResultSet rs = null;
stmt = connection.createStatement();
rs = stmt.executeQuery("SELECT Id FROM ACCOUNT");
while (rs.next()) {
System.out.println(rs.getString(1));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
I am more concerned with making driver work for SQL Workbench. Any help to resolve this will be really appreciated.
**** UPDATE ****
Thanks to @Mark Rotteveel based on his suggestion made changes to the code and post that code was successful. But need to make this driver work in SQL Workbench as well.
PreparedStatement preparedStatement = connection.prepareStatement("SELECT Id FROM Account limit 3");
preparedStatement = connection.prepareStatement("SELECT Id FROM Account limit 3");
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
System.out.println(resultSet.getString(1));
}
Upvotes: 3
Views: 4573