I'm trying to use ActiveJDBC with a DB whose driver does not support the Connection.prepareStatement(String, String[]) method. I'm getting the following exception when trying to insert:
org.javalite.activejdbc.DBException: java.sql.SQLFeatureNotSupportedException: [DataDirect][OpenEdge JDBC Driver]Unsupported method: Connection.prepareStatement(String, String[]), query: INSERT INTO ...
at com.ddtek.jdbc.openedgebase.ddb9.b(Unknown Source)
at com.ddtek.jdbc.openedgebase.ddb9.a(Unknown Source)
at com.ddtek.jdbc.openedgebase.ddb8.b(Unknown Source)
at com.ddtek.jdbc.openedgebase.ddb8.a(Unknown Source)
at com.ddtek.jdbc.openedgebase.BaseConnection.prepareStatement(Unknown Source)
at org.javalite.activejdbc.DB.execInsert(DB.java:597)
at org.javalite.activejdbc.Model.insert(Model.java:2618)
at org.javalite.activejdbc.Model.save(Model.java:2552)
at org.javalite.activejdbc.Model.saveIt(Model.java:2477)
...
Some other forms of prepareStatement are supported, e.g. prepareStatement (String), prepareStatement (String, int), etc.
Is there anything I can do to convince ActiveJDBC not to use the unsupported statement?
As you can see in the source , this is pretty much hard coded. So from the top of my mind you could either request a change in ActiveJDBC or go ahead wrapping your "flawed" Connection into a custom implementation and overriding this prepareStatement(String, String[])
public PreparedStatement prepareStatement(String qry, String[] autoIdColumns) {
return delegate.prepareStatement(qry);
}
Google returned some ideas for ConnectionWrapper implementations out there.
Please, look at databases supported by ActiveJDBC: http://javalite.io/activejdbc#supported-databases. Each one is thoroughly tested.
I am trying to run a spark application using sparkSQL inside, but whenever i use LEFT OUTER JOIN its giving me following error,
select a.name,b.phone FROM name a LEFT OUTER JOIN phone b ON (a.id=b.id)
java.io.FileNotFoundException: localhost:57067/broadcast_1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.spark.broadcast.HttpBroadcast$.read(HttpBroadcast.scala:196)
at org.apache.spark.broadcast.HttpBroadcast.readObject(HttpBroadcast.scala:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
But there is no problem for me if i use JOIN instead of it. What will be the issue ?
I am using Spark Version 1.0.0
Generally file not found exception are seen when there is issue in finding file during file operation. And if the SQL statement is the culprit of your exception you should have got SQlException, are you doing any file operations before doing the SQL operation.
Hi i have a Problem while inserting data in my databases ...
String query = "INSERT INTO gutscheine (code, Wert) values ("+Code+","+Wert+")";
SQLConnection sql = new SQLConnection("Gutscheine.db");
PreparedStatement ps;
try {
ps = sql.con.prepareStatement(query);
int i = ps.executeUpdate();
if (i == -1) {
System.out.println("db error : " + query);
}
} catch (SQLException e) {
e.printStackTrace();
}
sql.CloseConnection(); // my own funktion
My Error:
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: GUTSCHEINE
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at com.daniel.guthaben.Gutschein.<init>(Gutschein.java:33)
at com.daniel.guthaben.Main.main(Main.java:7)
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: GUTSCHEINE
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getTable(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readRangeVariableForDataChange(Unknown Source)
at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 4 more
Here i am trying adding context from the root user ... (on the left you can see the table exists)
http://i.stack.imgur.com/FS5ws.png
Sorry I was using diffrent databases ... :(
it's generally not advised to use string building for your query. String query = "INSERT INTO gutscheine (code, Wert) values (?, ?)"; and then running it through a safe query preparation is going to be better.
That said, the error sounds pretty obvious? user lacks privilege or object not found: GUTSCHEINE. Doesn't look like you're connecting as a particular user from your code, so I suspect you forgot to pass along your username and password when setting up the database connection. If that part's fine, verify Gutscheine.db exists.
The problem here is simple. When you are inserting string values, you need to enclose them in single quotes.
For example, "insert into table(col1, col2) values ('ABC','xyz');"
Have a look at the example provided in this link:
https://www.tutorialspoint.com/hsqldb/hsqldb_insert_query.htm
In your case, you need to enclose the values of Code and Wert in single quotes before you insert, or at the time of insert.
The following approach worked for me:
Code = "'" + Code + "'";
Wert = "'" + Wert + "'";
Use your insert query now, and it should work.
Even though hsql is quite forgiving and requires no infrastructure, you need to create the table upfront - e.g.
CREATE TABLE Gutscheine ( code varchar 20, Wert varchar 20 )
Also, you might want to read about SQL-Injection and use PreparedStatement. While you're at it, google for "little bobby tables"
I haven't run into privilege issues with hsql yet, but you might want to check how you open the connection, e.g. if you give a proper user account. You can actually check a proper one by looking at the hsql storage, which is clear text. It should contain the required user name - e.g. "SA"
Also, with that error message on google, several threads come up that suggest that hsql version upgrade might help, or that you ended up with a corrupt database after not executing "SHUTDOWN;" after creation of the database. Another one is the database name "null" in your .script file. Well, check them for yourself and try which solution matches your problem (the two linked threads point to several possible solutions):
http://sourceforge.net/p/hsqldb/mailman/message/28944633/
http://www.coderanch.com/t/460394/JDBC/databases/HSQLDB-user-lacks-privilege-object
my goal is to import data into a derby database. The data was extracted from a MySQL instance in form of a SQL dump and I took care with a script that I only use the insert-statements and also that the escaping of the MySQL specific syntax is transformed to Derby correctly.
To Test, I use the derby-maven-plugin:
export MAVEN_OPTS=-Xmx2048m; mvn derby:run
In the first step, I create the schema in the derby instance (using DDLUtils from MySQL, this works fine).
Second, I try to import the data. I use ij on the command line with the following (shortend) script:
CONNECT 'jdbc:derby://localhost:1527/foodmart';
SET SCHEMA APP;
autocommit off;
INSERT INTO "ACCOUNT" VALUES (1000,NULL,'Assets','Asset','~',NULL), (2000,NULL,'Liabilities','Liability','~',NULL),(3000,5000,'Net Sales','Income','+',NULL),(3100,3000,'Gross Sales','Income','+','LookUpCube(\"[Sales]\",\"(Measures.[Store Sales],\"+time.currentmember.UniqueName+\",\"+ Store.currentmember.UniqueName+\")\")'),(3200,3000,'Cost of Goods Sold','Income','-',NULL),(4000,5000,'Total Expense','Expense','-',NULL),(4100,4000,'General & Administration','Expense','+',NULL),(4200,4000,'Information Systems','Expense','+',NULL),(4300,4000,'Marketing','Expense','+',NULL),(4400,4000,'Lease','Expense','+',NULL),(5000,NULL,'Net Income','Income','+',NULL);
...
commit;
As you can see, for every row of a table there is a bracket containing the sample data.
There are of course several more insert statments for other tables. After finishing some inserts correctly, the bulk importing process chokes at a really big dataset (> 1000 rows) due to following exception (from the derby-logs):
java.lang.StackOverflowError
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.UnionNode.bindExpressions(Unknown Source)
... and many lines more repeatingly because of the recursive nature...
Cleanup action completed
ij prints on the command line:
FEHLER XJ001: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ001, SQLERRMC: java.lang.StackOverflowError^T^TXJ001.U
Is this meaning, that derby is not capable using SQL-bulk-import scenarios?
Should I instead switching to an csv based import?
I assume from the stacktrace method calls that derby is not able to create the query plan.
Could it be possible, that for every 'data bracket' of an insert statement it will create internly an UNION statement, adding a big amount of overhead to each INSERT query.
So should I try to split my long INSERT-statements in many concise statements?
I don't have the time to look at the derby sources, so please help me!
I just used many Import statements and it worked.
It seems that for every data bracket of an INSERT statement Derby generates a method call on the stack, leeding for many brackets to a stackoverflow due to many recursive method calls.
However You just need to transform an INSERT statement from
Insert INTO VALUES (1,2,3), ..., (4,5,6);
To multiple statements:
Insert INTO VALUES (1,2,3);
...
Insert INTO VALUES (4,5,6);
I have an in-memory HSQL database (v 1.8) up and running - I am able to connect to it using Java and run "CREATE TABLE" queries.
I am trying to create & run stored procedures and from the HSQL docs the way to do it is create an alias and have it point to a Java class. Then have the Java class do the necessary processing the stored procedure would do.
I have created an alias in HSQL using something like the following statement -
CREATE ALIAS MySPROC FOR "com.mypackage.MyClass.myFunction";
Then I try to run this SPROC using a Java code like the following -
java.sql.CallableStatement stmt = cnt.prepareCall(storedProcedureCall);
Where cnt is of type java.sql.Connection.
I am getting an error as follows -
java.lang.RuntimeException: java.sql.SQLException: Function not found com.mypackage.MyClass java.lang.ClassNotFoundException: com.mypackage.MyClass in statement [ CALL MySPROC(?,?,?) ]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcCallableStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareCall(Unknown Source)
etc.
What I understand is that I have to show HSQL the location of "com.mypackage.MyClass".
How do I do that?
Here is create procedure sql statement I have been using in 2.2.9:
drop procedure ms.cleanupLocations;
create procedure ms.cleanupLocations(myLocation int)
MODIFIES SQL DATA
BEGIN ATOMIC
delete from ms.mytable where myLocation = 0;
END;
Here is Java code to call it:
static void cleanupSigSumm(Connection cn, int locationNumber) throws SQLException {
CallableStatement proc = cn.prepareCall("{ call ms.cleanupSigSumm(?) }");
proc.setInt(1, locationNumber);
proc.execute();
}