Google BigQuery, Exception thrown for null value in prepared statement - jdbc

We are trying to load data to google bigquery using Jdbc (Simba driver). When trying to insert a null value in a prepared statement, we are getting an exception. This works when it is not a prepared statement. For example, the code (with the connection Url hidden):
import java.sql.*;
public class Program {
public static void main(String[] args) {
Program program = new Program();
try {
program.doStatement();
} catch (Exception e) {
e.printStackTrace();
}
try {
program.doPreparedStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
public Program() {}
public void doPreparedStatement() throws Exception {
try(Connection connection = getConnection()) {
PreparedStatement statement = connection.prepareStatement("INSERT INTO test1.my_table (CONTACT, COMPANY, ADDRESS, CITY, STATE, ZIP) VALUES (?,?,?,?,?,?)");
statement.setString(1, "MyContact");
statement.setString(2, "MyCompany");
statement.setString(3, "MyAddress");
statement.setString(4, "MyCity");
statement.setString(5, "MyState");
statement.setNull(6, Types.BIGINT);
System.err.println("Executing prepared statement...");
int count = statement.executeUpdate();
}
System.err.println(" done.");
}
public void doStatement() throws Exception {
try(Connection connection = getConnection()) {
String create_command =
"CREATE TABLE test1.my_table ( CONTACT STRING, COMPANY STRING, ADDRESS STRING, CITY STRING, STATE STRING, ZIP STRING )";
Statement createStatement = connection.createStatement( );
System.err.println("Create table.");
createStatement.execute(create_command);
System.err.println("Table created.");
System.err.println("Executing statement...");
Statement statement = connection.createStatement();
int count = statement.executeUpdate("INSERT INTO test1.my_table (CONTACT, COMPANY, ADDRESS, CITY, STATE, ZIP) VALUES ('MyContact','MyCompany','MyAddress','MyCity','MyState',NULL)");
}
System.err.println(" done.");
}
private Connection getConnection() throws Exception
{
Connection connection = null;
connection = DriverManager.getConnection(CONNECTION_URL);
return connection;
}
}
Produces the following output:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Create table.
Table created.
Executing statement...
done.
Executing prepared statement...
java.sql.SQLException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unparseable query parameter `` in type `TYPE_INT64`, Bad int64 value: null value: 'null'
at com.simba.googlebigquery.googlebigquery.client.BQClient.insertJob(Unknown Source)
at com.simba.googlebigquery.googlebigquery.client.BQClient.executeQuery(Unknown Source)
at com.simba.googlebigquery.googlebigquery.dataengine.BQAbstractExecutor.execute(Unknown Source)
at com.simba.googlebigquery.googlebigquery.dataengine.BQSQLExecutor.execute(Unknown Source)
at com.simba.googlebigquery.jdbc.common.SPreparedStatement.executeWithParams(Unknown Source)
at com.simba.googlebigquery.jdbc.common.SPreparedStatement.executeAnyUpdate(Unknown Source)
at com.simba.googlebigquery.jdbc.common.SPreparedStatement.executeUpdate(Unknown Source)
at Program.doPreparedStatement(Program.java:35)
Caused by: com.simba.googlebigquery.support.exceptions.GeneralException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: Unparseable query parameter `` in type `TYPE_INT64`, Bad int64 value: null value: 'null'
... 8 more

I've found this to work when adding BigQuery support to jOOQ (see e.g. #11841), for numeric types:
statement.setBigDecimal(6, null);
The BigDecimal type is the only numeric JDBC type that is not primitive. For other data types, use their respective setter if it is supported, or setString(6, null), if Simba still doesn't like NULL values for the respective type, including e.g.:
Boolean
Date
Time
If in doubt about any conversion problems (e.g. because Simba seems to bind BigDecimal as STRING, currently, at least in version 1.2.13.1016), make sure you cast the bind variable, e.g.:
CAST(? AS INT64)

Related

Using H2 alias for mocking stored procedure which has output parameters. Is this even possible with H2?

I have created an H2 alias function which is being called when I execute the corresponding spring jdbc StoredProcedure.
public static ResultSet dao_cashflow_read(Integer contractId, Integer contractVersion, Date rateDtmDate, String refSrc,
String rateStatus, String rateType, String message, Integer rowCount) throws SQLException, IOException {
File f = new File(FixingDaoIT.class.getResource("/").getFile().concat("csv/ldn/fixing.csv"));
return new Csv().read(new FileReader(f), null);
}
This part is working as expected as the associated row mapper function parses the result set correctly and generates the entity objects. The problem is, the JdbcTemplate class then attempts to extract the associated output parameters that were registered with the StoredProcedure implementation. Which in turn calls the method below in class JdbcCallableStatement.java
private JdbcResultSet getOpenResultSet() throws SQLException {
try {
checkClosed();
if (resultSet == null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
if (resultSet.isBeforeFirst()) {
resultSet.next();
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
}
}
This call fails as the resultSet reference is now null and it throws the DbException NO_DATA_AVAILBLE
If I run the application against Sybase, the output params are as expected. Is this an issue with H2 not supporting output params?

Apache Drill JDBC connectivity through java code is giving error:Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException

i am trying drill-jdbc connectivity through java code.
Error is:-
java.sql.SQLException: Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException: CONNECTION : java.net.ConnectException: Connection refused: no further information: localhost/127.0.0.1:31010
So the steps followed are below:-
wget http://www-eu.apache.org/dist/drill/drill-1.12.0/apache-drill-1.12.0.tar.gz
tar -xvf apache-drill-1.12.0.tar.gz
cd apache-drill-1.12.0
cd bin
./drillbit.sh start -Ddrill.exec.http.port=8765
To check check its running under zookeeeper
cd /usr/hdp/current/zookeeper-client
./zkCli.sh
ls /drill
In apache-drill-1.12.0/bin
started drill-localhost # ./drill-localhost
received contents "OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0 apache drill 1.12.0"
normal database queries were working properly
is there any dependancy between jdk -version?
Java Code:-
import java.sql.*;
public class DrillJDBCExample {
static final String JDBC_DRIVER = "org.apache.drill.jdbc.Driver";
static final String DB_URL = "jdbc:drill:drillbit=localhost:";//"jdbc:drill:zk=localhost:2181";
//"jdbc:drill:drillbit=localhost";
static final String USER = "admin";
static final String PASS = "admin";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
/* Class.forName("org.apache.drill.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=127.0.0.1:8765");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT * from cp.`employee`");
while(rs.next()){
System.out.println(rs.getString(1));
}
}*/
Connection conn = null;
Statement stmt = null;
try{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
// Perform a select on data in the classpath storage plugin.
String sql = "select employee_id,first_name,last_name from cp.`employee.json`";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int id = rs.getInt("employee_id");
String first = rs.getString("first_name");
String last = rs.getString("last_name");
System.out.print("ID: " + id);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
rs.close();
stmt.close();
conn.close();
} catch(SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch(Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
try{
if(stmt!=null)
stmt.close();
} catch(SQLException se2) {
}
try {
if(conn!=null)
conn.close();
} catch(SQLException se) {
se.printStackTrace();
}
}
}
}
Error Logs:-
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.sql.SQLException: Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at org.apache.drill.jdbc.impl.DrillConnectionImpl.<init>(DrillConnectionImpl.java:162)
at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)
at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)
at oadd.net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)
at org.apache.drill.jdbc.Driver.connect(Driver.java:72)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.mapr.drill.DrillJDBCExample.main(DrillJDBCExample.java:29)
Caused by: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at oadd.org.apache.drill.exec.client.DrillClient$FutureHandler.connectionFailed(DrillClient.java:675)
at oadd.org.apache.drill.exec.rpc.user.QueryResultHandler$ChannelClosedHandler.connectionFailed(QueryResultHandler.java:389)
at oadd.org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$HandshakeSendHandler.failed(BasicClient.java:254)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$RpcListener.setException(RequestIdMap.java:134)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:74)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:64)
at oadd.com.carrotsearch.hppc.IntObjectHashMap.forEach(IntObjectHashMap.java:692)
at oadd.org.apache.drill.exec.rpc.RequestIdMap.channelClosed(RequestIdMap.java:58)
at oadd.org.apache.drill.exec.rpc.RemoteConnection.channelClosed(RemoteConnection.java:175)
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:167)
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:146)
at oadd.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
at oadd.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:567)
at oadd.io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:406)
at oadd.io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:82)
at oadd.io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:943)
at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:592)
at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:584)
at oadd.io.netty.channel.DefaultChannelPipeline$HeadContext.close(DefaultChannelPipeline.java:1099)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.ChannelDuplexHandler.close(ChannelDuplexHandler.java:73)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:466)
at oadd.org.apache.drill.exec.rpc.RpcExceptionHandler.exceptionCaught(RpcExceptionHandler.java:39)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:79)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:809)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:341)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:242)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847)
at oadd.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at oadd.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at oadd.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Unknown Source)
Caused by: oadd.org.apache.drill.exec.rpc.ChannelClosedException: Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:166)
... 52 more
Followed documents are:-
1) https://drill.apache.org/docs/
2) https://community.hortonworks.com/articles/10551/apache-drill-unofficial-introduction.html

Derby DB: Table/View doesn't exist ERROR 42X05

I installed a Derby DB and I opened a connection named "MyDbTest".
I created a table named BOOK for "MyDbTest" connection by the SQL command:
CREATE TABLE BOOK(ID INT, DESCRIPTION VARCHAR(20), UNITCOST VARCHAR(20), ISBN VARCHAR(20), NBOFPAGES INT);
I ran the Derby server by using the command: "startNetworkServer.bat"
I ran the following code (using Open JPA):
public class Main {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
System.out.println("\n\n>>> Executing : " + Main.class.toString() + " <<<\n");
persistBook(new Book(new Long(5000), "H2G2", "Best IT Scifi Book", new Float(12.5), "1234-5678-5678",
new Integer(247)));
Book book = findBook(new Long(5000));
System.out.println("# " + book);
}
/**
* Gets a database connection
*/
static {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:derby://localhost:1527/MyDbTest;create=true", "app", "app");
}
/**
* Persists the book to the database
*/
private static void persistBook(Book book) throws SQLException {
String query = "INSERT INTO BOOK (ID, TITLE, DESCRIPTION, UNITCOST, ISBN, NBOFPAGE) VALUES (?, ?, ?, ?, ?, ?)";
try (PreparedStatement stmt = getConnection().prepareStatement(query)) {
stmt.setLong(1, book.getId().longValue());
stmt.setString(2, book.getTitle());
stmt.setString(3, book.getDescription());
stmt.setFloat(4, book.getUnitCost().longValue());
stmt.setString(5, book.getIsbn());
stmt.setInt(6, book.getNbOfPage().intValue());
stmt.executeUpdate();
}
}
}
and I got an Error:
Exception in thread "main" java.sql.SQLSyntaxErrorException:
Table/View 'BOOK' does not exist.
Caused by: ERROR 42X05: Table/View 'BOOK' does not exist.
I also read the solution proposed in this post: Is it necessary to create tables each time you connect the derby database?.
Unfortunately, none of them helped me.
I changed "jdbc:derby://localhost:1527/MyDbTest;create=true" to "jdbc:derby://localhost:1527/MyDbTest;create=false"
I don't use "in-memory" configuration in Derby.
I don't think I connect to the DB as another user (I'm not sure about it. How can I check it?).
I had this error because I was using the database name in the SELECT statement instead of the name of the table.

java.sql.SQLSyntaxErrorException: The class 'TempSP' does not exist or is inaccessible

I am trying to create stored procedure in derby database using java.
public class TestDrive {
public static void main (String[] args) throws SQLException, ClassNotFoundException{
Connection conn = null;
CallableStatement stmt = null;
try {
try{
Class.forName("org.apache.derby.jdbc.ClientDriver").;
} catch(ClassNotFoundException e){
System.out.println("Can't load the database driver");
return;
}
conn = DriverManager.getConnection("jdbc:derby://localhost:1527/Connections_DB", "Connections_DB", "KaayRey");
stmt = conn.prepareCall("CALL NameOFstoreProcedure4( ?, ? )");
stmt.setString(1, "Kitu");
stmt.setString(2, "KaayChalay");
stmt.execu`enter code here`te();
} finally {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
} //END OF CLASS TestDrive.java
TempSP.java Code:-
public class TempSP {
public static void NameOFSP(String uname, String upass)throws SQLException {
PreparedStatement stmt = null;
ResultSet res = null;
String message = null ;
try{
try{`enter code here`
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch(ClassNotFoundException e){
System.out.println("Can't load the database driver");
return;
}
String dbURL = "jdbc:derby://localhost:1527/Connections_DB";
Connection conn = DriverManager.getConnection(dbURL, "Connections_DB", "KaayRey");
Stri`enter code here`ng sql = "INSERT INTO USERS2(USER_NAME, USER_PASSWORD) VALUES(?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uname);
stmt.setString(2, upass);
int row = stmt.executeUpdate(sql);
}catch (SQLException ex) {
message = "ERROR 1 : " + ex.getMessage();
ex.printStackTrace();
}
}
} // END OD TempSP.java
But when I run run my TestDrive.java file it will gives me following error:-
"Exception in thread "main" java.sql.SQLSyntaxErrorException: The class 'TempSP' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareCall(Unknown Source)
at FriendsConnectionPack.TestDrive.main(TestDrive.java:34)
Caused by: org.apache.derby.client.am.SqlException: The class 'TempSP' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepare(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepare(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepare_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepare(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareCallX(Unknown Source)
... 2 more
Caused by: org.apache.derby.client.am.SqlException: Java exception: 'TempSP: java.lang.ClassNotFoundException'.
... 13 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)"
Derby Stored Procedure Code As Follows:-
CREATE PROCEDURE NameOFstoreProcedure5(User_Name VARCHAR(50), User_Password VARCHAR(20))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
'FriendsConnectionPack.TempSP.NameOFSP'
I encountered the same problem and the solution was setting the stored procedure's code in a jar file and then using the derby's systems procedures to register the jar and setting the derby's class path as shown next
To add a jar to Derby:
CALL sqlj.install_jar('PATH TO JAR FILE', 'DATABASE.IDENTIFIER FOR THE JAR', 0)
To add the jar to derby's internal classpath
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(
'derby.database.classpath',
'colonSeparatedJarFiles')
Hope this helps someone

hive jdbc throws "Error running query: java.lang.NullPointerException"

FROM cr_expanded_crcs_halen c INSERT OVERWRITE TABLE merge_result SELECT 'crcs', operator_id, instance_id, ts, user, application, actualconn, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
I try to insert data to table merge_result using above sql with jdbc, found errors as below
Exception in thread "main" java.sql.SQLException: Error running query: java.lang.NullPointerException
at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:159)
at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:147)
at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:182)
at org.apache.solr.handler.dataimport.scheduler.HiveClient.main(HiveClient.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
but the data has been inserted successfully.
Any body can help me ?
I have had the same error.
Unfortunately, I can't found why it's failing, but I found a workaround.
The problem occurs when you use the word NULL into a select statement thought JDBC, My ugly solution was replace NULL by an udf "null_value()"
I will open a jira with this problem
#Description(name="null_value", value="_FUNC() return null")
#UDFType(deterministic=true, stateful=false)
public class NullValue extends GenericUDF {
#Override
public ObjectInspector initialize(ObjectInspector[] arguments)
throws UDFArgumentException {
return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
}
#Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
return null;
}
#Override
public String getDisplayString(String[] children) {
return "keys_to_lower_"+children[0];
}
}
Thanks,
Gabo

Resources