I wish to connect to SSAS 2012 using Java and have tried olap4j driver for the same.
I am working on Linux (Ubuntu 14.04) platform.
I have read that Olap4j works for Windows but will it work on Linux ?
I have written some Java code which gives runtime error. This error is because the Linux machine is unable to connect to SSAS.
I have set http access and IIS server and using msmdpump.dll to connect.
Below is the Java code and the error.:
CODE
package ssas;
import java.sql.Connection;
//import java.lang.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.olap4j.Cell;
import org.olap4j.CellSet;
import org.olap4j.OlapConnection;
import org.olap4j.OlapException;
import org.olap4j.OlapStatement;
import org.olap4j.OlapWrapper;
import org.olap4j.Position;
import org.olap4j.metadata.Member;
public class connexionSSAS
{
public static void main(String[] args) throws ClassNotFoundException,
OlapException {
Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:xmla:Server=http://01XXXXXXXX/olap/msmdpump.dll;" +
"Catalog=sample_Cube");
} catch (SQLException e) {
e.printStackTrace();
}
if (null == connection) {
System.out.println("Cnul");
}
OlapWrapper wrapper = (OlapWrapper) connection;
OlapConnection olapConnection = null;
try {
olapConnection = wrapper.unwrap(OlapConnection.class);
} catch (SQLException e) {
e.printStackTrace();
}
olapConnection.setCatalog("sample_Cube");
OlapStatement statement = null;
CellSet cellSet = null;
System.out.println(olapConnection.getCatalog());
try {
statement = (OlapStatement) olapConnection.createStatement();
CellSet=statement.executeOlapQuery(
"Summarize(FactDiagnosis,FactDiagnosis[ImportDateKey])");
args}
catch(SQLException e) {
e.printStackTrace();
}
}
}
ERROR
Exception in thread "main" java.lang.RuntimeException: org.olap4j.OlapException: This connection encountered an exception while executing a query.
at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:96)
at org.olap4j.driver.xmla.DeferredNamedListImpl.size(DeferredNamedListImpl.java:116)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapDatabase(XmlaOlap4jConnection.java:451)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapCatalogs(XmlaOlap4jConnection.java:527)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.setCatalog(XmlaOlap4jConnection.java:483)
at ssas.connexionSSAS.main(connexionSSAS.java:49)
Caused by: org.olap4j.OlapException: This connection encountered an exception while executing a query.
at org.olap4j.driver.xmla.XmlaHelper.createException(XmlaHelper.java:43)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:878)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:137)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:67)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getDatabaseProperties(XmlaOlap4jDatabaseMetaData.java:1044)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.makeConnectionPropertyList(XmlaOlap4jConnection.java:324)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.generateRequest(XmlaOlap4jConnection.java:1037)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.populateList(XmlaOlap4jConnection.java:849)
at org.olap4j.driver.xmla.DeferredNamedListImpl.populateList(DeferredNamedListImpl.java:136)
at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:90)
... 5 more
This code will run if I comment the statements containing 'OlapConnection'.
Any help would be appreciated.
Related
I have this code:
package routines;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Properties;
public class SnowflakeDriverExample {
public static void main() throws Exception
{
System.out.println("Create JDBC connection");
Connection connection = getConnection();
System.out.println("Done creating JDBC connectionn");
}
private static Connection getConnection()
throws SQLException
{
try
{
Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
}
catch (ClassNotFoundException ex)
{
System.err.println("Driver not found");
}
// build connection properties
Properties properties = new Properties();
properties.put("user", "my_user");
properties.put("password", "my_password");
properties.put("db", "my_db");
properties.put("schema", "my_schema");
// create a new connection
String connectStr = System.getenv("SF_JDBC_CONNECT_STRING");
// use the default connection string if it is not set in environment
if(connectStr == null)
{
connectStr = "https://my_account.snowflakecomputing.com/";
}
return DriverManager.getConnection(connectStr, properties);
}
}
now, when I call:
SnowflakeDriverExample.main();
I get this error:
Exception in component tJava_1 (j_example)
java.sql.SQLException: No suitable driver found for https://my_account.snowflakecomputing.com/
when I iterated over drivers and printed them- I got this one:
net.snowflake.client.jdbc.SnowflakeDriver
looks like I have the correct snowflake driver, and I the connectionStr is my actual snowflake url.
so what's the problem?
ok.
the problem was my connectionStr, which was:
connectStr = "https://my_account.snowflakecomputing.com/";
and should be:
connectStr = "jdbc:snowflake://my_account.snowflakecomputing.com/";
now everything is fine. thanks a lot!
I am trying to connect sqlite db browser with java using nano editor i am very new here. i have
followed some youtube videos but i am stacking at mid can anyone please help
here is my code.
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SqliteDB{
Connection c = null;
Statement stmt = null;
SqliteDB(){
try{
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:signup.db");
System.out.println("Connected to DB");
}
catch(Exception e){
System.out.println("Error: "+ e.getMessage());
}
}
}
Error: org.sqlite.JDBC
thank you guys for helping.
I think that you have not imported library org.sqlite.JDBC in your project, Class.forName() return class that exists, when you get error like this it says that this class is not exists.
First of all download library from: https://bitbucket.org/xerial/sqlite-jdbc/downloads/
Then import in your project and that's how you should write the code:
public static void main(String[] args) throws SQLException {
org.sqlite.JDBC j = new org.sqlite.JDBC();
Connection c = DriverManager.getConnection("jdbc:sqlite:signup.db");
//do stuff here
}
This question already has an answer here:
MySQL Connect via proxy in Java
(1 answer)
Closed 2 years ago.
In Java, I would like to make a connection to a MySQL server which is on the web from a client computer that is behind a http proxy. I have read few solutions some say http tunnelling might work and some suggest a very old link from oracle which is not available anymore. So the question is:
How can we connect to a MySQL server from a computer which is behind a http proxy?
You can try the following code and see if it works. It worked for me over TCP
package indika.jdbc.connectivity;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class ConnectOverProxy {
public static void main(String[] args) {
new ConnectOverProxy();
}
public ConnectOverProxy() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
Properties info = new Properties();
//info.put("proxy_type", "4"); // SSL Tunneling
info.put("proxy_host", "[proxy host]");
info.put("proxy_port", "[proxy port]");
info.put("proxy_user", "[proxy user]");
info.put("proxy_password", "[proxy password]");
info.put("user", "[db user]");
info.put("password", "[db pass word]");
conn = DriverManager.getConnection("jdbc:mysql://[db host]/",info);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select NOW()");
rs.next();
System.out.println("Data- " + rs.getString(1));
rs.close();
stmt.close();
conn.close();
} catch (SQLException er) {
er.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Also look at "http://www.idssoftware.com/jdbchttps.html", However I have not used this personally.
i Have work on Hadoop/hive. i have install hadoop and hive which is running fine on command prompt.i have also create a MySQL meta store of hive.I have define HIVE-DB database name in hive-site.xml file.The same name database is available in MySQL>HIVE-DB .but the table which is create on hive command prompt is not available in mysql command Prompt.
And when i want to create a hive jdbc Connection then get following error..First it is my Program to create a jdbc connection
package aa;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main
{
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String args[])
{
try {
Class.forName(driverName);
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
try
{
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10001/default", "", "");
Statement stmt = con.createStatement();
String tableName = "recordssss";
stmt.executeQuery("create table"+tableName+"(id int,name string)");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
and then following error is display... because i have start hive as a hive server i.e
**$HIVE_HOME/bin/hive --service hiveserver -p 10001**
xception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.hive.service.ThriftHive$Client.sendBase(Ljava/lang/String;Lorg/apache/thrift/TBase;)V
at org.apache.hadoop.hive.service.ThriftHive$Client.send_execute(ThriftHive.java:110)
at org.apache.hadoop.hive.service.ThriftHive$Client.execute(ThriftHive.java:102)
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:187)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at aa.Main.main(Main.java:25)
enter code here
so pls help me i have describe the problem to you so pls dear anyone help me
It seems like you are not using appropriate library in your client code. The jars you are using might be of wrong versions. Please check those once.
I am trying to connect to mysql from java web application in eclipse.
Connection con = null;
try {
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/db_name","root" ,"");
if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {
System.out.println(e.toString());
}
}
I am always getting the Exception: com.mysql.jdbc.Driver
I have downloaded this jar http://forums.mysql.com/read.php?39,218287,220327
import it to the "java build path/lib"
the mysql version is 5.1.3 under.
running:
mysql 5.1.3 (db is up and running queries form PHP)
windows XP
Java EE
you say you placed the JAR on the build path, is it in the runtime class path? you said "java EE", so i assume you are deploying this as a web app? in that case you need to put the JDBC JAR file into WEB-INF/lib of your web app.
You have to download the mysql jdbc connector und use it as lib. You can get it here:
http://www.mysql.com/downloads/connector/j/
Have u added it in your build configuration also, if the location is not in classpath then it wont work by mere keeping it in lib folder.
check your .classpath file
You can find a full documentation (Chapter 14) on how to connect to MySQL database through any web application (JBOSS, Glassfish etc...), if you download the MySQL JDBC driver.
After doing your configuration, you have to get the connection from your server by getting your server connection ressource.
Here is a sample code of how to get a connection ressource from a Glassfish server :
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
#Stateless
public class AppConnection {
private InitialContext context;
private DataSource source;
private Connection connection;
public AppConnection() {
this.initConnection();
}
private void initConnection() {
try {
context = new InitialContext();
source = (DataSource)context.lookup("jdbc/MySQLDataSource");
connection = source.getConnection();
} catch (SQLException ex) {
Logger.getLogger(AppConnection.class.getName()).log(Level.SEVERE, null, ex);
} catch (NamingException ex) {
Logger.getLogger(AppConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Connection getContextConnection() {
return connection;
}
public void closeContextConnection() throws SQLException {
if(connection != null) {
connection.close();
}
}
}
Note that this class is an EJB and "jdbc/MySQLDataSource" is the name of the connection configured on your server. It can be inject in other EJB to get your current connection and create other needed objects as Statements or Resultsets.