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.
Related
Using UCanAccess for the first time for a project and I am having a lot of trouble inserting a row into one of my database tables (in Microsoft Access).
My code makes sense but once I execute I end up getting the same error every time, even though NetBeans is able to connect to my database.
package Vegan;
import java.sql.Connection;
import java.sql.DriverManager;
public class connectionString {
static Connection connection = null;
public static Connection getConnection()
{
try
{
connection = DriverManager.getConnection("jdbc:ucanaccess://C://MyDatabase1.accdb");
System.out.println("---connection succesful---");
}
catch (Exception ex)
{
System.out.println("Connection Unsuccesful");
}
return connection;
}
package Vegan;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DB {
private static ResultSet rs = null;
private static PreparedStatement ps = null;
private static Connection connection = null;
public DB() {
connection = connectionString.getConnection();
}
public void AddTest() {
try {
String sql = "INSERT INTO CategoryTbl(CategoryName) VALUES (?)";
ps = connection.prepareStatement(sql);
ps.setString(1, "Flours");
ps.executeUpdate();
System.out.println("Inserted");
} catch (Exception ex) {
System.out.println(ex.getLocalizedMessage().toString());
}
}
After that, when I execute the the AddTest() method, I get this system output:
run:
---connection succesful---
java.nio.channels.NonWritableChannelException
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:724)
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(PageChannel.java:297)
UCAExc:::3.0.6 null
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(PageChannel.java:234)
at com.healthmarketscience.jackcess.impl.TableImpl.writeDataPage(TableImpl.java:1375)
at com.healthmarketscience.jackcess.impl.TableImpl.addRows(TableImpl.java:1624)
at com.healthmarketscience.jackcess.impl.TableImpl.addRow(TableImpl.java:1462)
at net.ucanaccess.converters.UcanaccessTable.addRow(UcanaccessTable.java:44)
at net.ucanaccess.commands.InsertCommand.insertRow(InsertCommand.java:101)
at net.ucanaccess.commands.InsertCommand.persist(InsertCommand.java:148)
at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:315)
at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:161)
at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50)
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253)
at Vegan.DB.AddTest(DB.java:91)
at Vegan.TestDB.main(TestDB.java:17)
BUILD SUCCESSFUL (total time: 1 second)
With no changes being made to the database when I check on it again Access.
What could be causing this, and what does the error message mean? Thank you
"java.nio.channels.NonWritableChannelException" means that the database file cannot be updated. In your case that was because the database file was in the root folder of the Windows system drive (C:\) and mere mortals have restricted permissions on that folder.
Solution: Move the database file to a folder where you have full write access.
I'm trying to insert rows in SQLite embedded DB in java. after adding changes are visible in that program alone. I can't see the changes in sqlite manager. When I try to insert a row in sqlite manager values that inserted which are shown in the program gets deleted. And showing those row that I added using sqlite manager. Please help..
connection class
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class HsqlConn {
//public static void main(String[] args) {
public static Connection hconn = null;
public static Statement hstmt = null;
public static PreparedStatement pst = null;
public static void hConnectDb(){
try{
Class.forName("org.sqlite.JDBC");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL resource = classLoader.getResource("PS/PSDB.sqlite");
hconn = DriverManager.getConnection("jdbc:sqlite::resource:"+resource);
}
catch(Exception se){
//Handle errors for JDBC
se.printStackTrace();
}
}
}
main class using that db
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
hConnectDb();
String sql1 = "Insert into Bill (billNo,date,principal,principalText,custId,dueDate) values (?,?,?,?,?,?)";
pst = hconn.prepareStatement(sql1);
pst.setString(1,BillNoField.getText());
pst.setString(2,dateField1.getText());
pst.setString(3,PrincipalField.getText());
pst.setString(4,PrincipaTextField.getText());
pst.setString(5,custIdField.getText());
pst.setString(6,dueDateField.getText());
pst.executeUpdate();
pst.close();
hconn.close();
JOptionPane.showMessageDialog(null, "saved");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
According to the documentation of sqlite-jdbc, connection URL strings beginning with "jdbc:sqlite::resource:" are for loading read-only SQLite databases:
2009 May 19th: sqlite-jdbc-3.6.14.1 released.
This version supports "jdbc:sqlite::resource:" syntax to access read-only DB files contained in JAR archives, or external resources specified via URL, local files address etc. (see also the
You need to specify a file in the filesystem containing your SQLite database. On Windows, an example is:
Connection connection = DriverManager.getConnection("jdbc:sqlite:C:/work/mydatabase.db");
and on UNIX-like systems, an example is:
Connection connection = DriverManager.getConnection("jdbc:sqlite:/home/leo/work/mydatabase.db");
I would liked to run a .sql file into postgresql using java. I've been able to do it in phpmyadmin but i guess it's not the same for postgresql. I didn't find anything that can help me out on the internet. Can someone please advice?
My .sql file CONTAINS :
Create Database IF NOT EXISTS Student;
This is what i've done in phpmyadmin and it did worked. So that's what am trying to do but this time using postgresql.
Here is my code for phpmyadmin: I've used IBATIS
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.DriverManager;
import org.apache.ibatis.jdbc.ScriptRunner;
public class Main {
public static void main(String[] args) {
String script = "Entity.sql";
try {
Class.forName("com.mysql.jdbc.Driver");
new ScriptRunner(DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mysql", "root", ""))
.runScript(new BufferedReader(new FileReader(script)));
} catch (Exception e) {
System.err.println(e);
}
}
}
Can you please help?
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.
In this code class.forname it show error that class not found
so help me with this code because my is a local database application
I am using sqlite database.
package appview;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Databaseconnection {
Connection connection = null;
public static Connection connection2()
{
try
{
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\Jainam\\Java Application\\JPH\\src\\database\\jph_db.sqlite");
return connection;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
}
You have to declare the url this way: jdbc:sqlite:/DRIVE:/dirA/dirB/dbfile
DriverManager.getConnection("jdbc:sqlite:/C:/Users/Jainam/Java Application/JPH/src/database/jph_db.sqlite");
See Here for more informations
ClassNotFoundException means Java is not able to find the org.sqlite.JDBC class. You need to Download sqlite-jdbc-3.6.20.1.jar and put it in your class-path before running it.
here check database connectivity.
class not found ? then go for DDMS->FILE EXP-> SDCARD -> INSERT UR SQLITE.DB file.It will run proper.