Weird java.sql.SQLException error - java

I have a weird issue and most the stuff I seem to find on the web is referring to a driver or connection problem...
I am parsing threw a dBASE table to get some id numbers:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cnxn = DriverManager.getConnection("jdbc:odbc:dBASE Files;DefaultDir=\"C:\"");
Statement stmt = cnxn.createStatement();
command = "SELECT * FROM table";
ResultSet result = stmt.executeQuery(command);
while (result.next()) {
System.out.println(result.getInt(1));
}
The result that i get in the console is
1
2
3
4
...
1312
1313
1314
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
the line that generated the error is:
System.out.println(result.getInt(1));
Since i am getting a result out of it, I don't think it's a connection error or a driver one. I looked at the table and I don't seem to have anything wrong with the row 1315, i tried deleting it and nothing. Btw the table used has 2376 rows.
I have tried with another table with a different length and I also get the error after 417 rows.
Just in case it helps I am on windows 7, 64 bit, the tables are dBASE IV.
Thx in advance!

Another idea still. How about selecting 1,314 records from the table, but with a different range (for example, rows 1,000 -> 2,313)? I am wondering if the error still occur.

Related

Google Big Query using Simba Jdbc Driver gives unknown error, if size is greater than 26 characters is in compare string

We are using simba jdbc driver to connect to Big query from our application. We found that if the query contains IN clause with an & in the values the jdbc driver gives Metadata type error.
Ex query:
Select * from my_big_table where channel IN ("LOCAL & TRADITIONAL GROCERY")
com.simba.support.exceptions.GeneralException: Error message not
found: METADATA_INCORRECT_TYPE_ERR. Can't find resource for bundle
java.util.PropertyResourceBundle, key METADATA_INCORRECT_TYPE_ERR at
com.simba.googlebigquery.utils.BQCoreUtils.convertSqlTypeToBigQueryType(Unknown
Source) ~[GoogleBigQueryJDBC42.jar:na] at
com.simba.googlebigquery.dataengine.BQSQLExecutor.execute(Unknown
Source) ~[GoogleBigQueryJDBC42.jar:na] at
com.simba.jdbc.common.SPreparedStatement.executeWithParams(Unknown
Source) ~[GoogleBigQueryJDBC42.jar:na] at
com.simba.jdbc.common.SPreparedStatement.executeQuery(Unknown Source)
~[GoogleBigQueryJDBC42.jar:na] at
org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:688)
~[spring-jdbc-4.2.6.RELEASE.jar:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:629)
~[spring-jdbc-4.2.6.RELEASE.jar:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:680)
~[spring-jdbc-4.2.6.RELEASE.
Is there way to by pass this?
Link to the issue in Big Query Issue tracker:
http://code.google.com/p/google-bigquery/issues/detail?id=928
NOTE: Previously I had said the issue is with having '&' in the value. But on further investigation I found it has nothing to do with & in value but with the length of the value in the IN Clause is equal to or greater than 27

java.util.regex.PatternSyntaxException with UCanAccess

I am trying to connect to an Access database with Java 8 like in this answer :
Manipulating an Access database from Java without ODBC
I am unfamiliar with the creation/design of the DB.
The connection seems to work because I get a few error messages like this :
WARNING:Error in the metadata of the table MB02: table's row count in
the metadata is 556 but 557 records have been found and loaded by
UCanAccess. All will work fine, but it's better to repair your
database.
And I have this method trying to pull something out of the DB with an SQL SELECT Statement :
public void searchDatabase()
throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
Connection con = DriverManager
.getConnection("jdbc:ucanaccess:///C:/Users/Blabla.mdb");
Statement stmt = con.createStatement();
String query = "SELECT * FROM MB01";
ResultSet resultSet = stmt.executeQuery(query);
while(resultSet.next()){
System.out.println(resultSet.getString(1));
}
}
I keep getting this error :
Exception in thread "main" java.util.regex.PatternSyntaxException:
Dangling meta character '?' near index 19 MB 01 BEZAHLT ???
^ at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at
java.util.regex.Pattern.expr(Unknown Source) at
java.util.regex.Pattern.compile(Unknown Source) at
java.util.regex.Pattern.(Unknown Source) at
java.util.regex.Pattern.compile(Unknown Source) at
java.lang.String.replaceAll(Unknown Source) at
net.ucanaccess.converters.SQLConverter.replaceWhiteSpacedTableNames0(SQLConverter.java:547)
at
net.ucanaccess.converters.SQLConverter.replaceWhiteSpacedTables(SQLConverter.java:526)
at
net.ucanaccess.converters.SQLConverter.convertSQL(SQLConverter.java:372)
at
net.ucanaccess.converters.SQLConverter.convertSQL(SQLConverter.java:472)
at
net.ucanaccess.jdbc.UcanaccessStatement.convertSQL(UcanaccessStatement.java:57)
at
net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:206)
at DBCrawler.searchDatabase(DBCrawler.java:27)
Line 27 is where the error is thrown is :
ResultSet resultSet = stmt.executeQuery(query);
The thing is I can leave the query String empty or put any nonsense values in it and I still get the error.
Where do I start searching for the problem or how can I fix this?
I created an Access database with a table named 19 MB 01 BEZAHLT ??? and was able to reproduce your issue with UCanAccess 3.0.5. The problem will be was fixed in a future release of UCanAccess 3.0.6.

NullPointerException while accessing HSQLDB database

I am accessing HSQLDB through A jdbc drive in my java program. The script file of the database is as follows.
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE CACHED TABLE TBL1(ID CHAR(5),NAME VARCHAR(11),ZIP VARCHAR(11))
CREATE UNIQUE INDEX IDX_ID ON TBL1(ID)
CREATE CACHED TABLE TBL2(ID CHAR(5),STREET CHAR(5))
CREATE INDEX IDX_RS_ID ON TBL2(ID)
CREATE CACHED TABLE TBL3(ID VARCHAR(8) NOT NULL PRIMARY KEY,LON FLOAT,LAT FLOAT)
CREATE GLOBAL TEMPORARY MEMORY TABLE OVERLAY(ID CHAR(8),AROUTE CHAR(10),ZROUTE
CHAR(10),TYPE CHAR(8)) ON COMMIT PRESERVE ROWS
SET TABLE TBL1 INDEX'4490648 5643624 0'
SET TABLE TBL2 INDEX'529105280 529105280 0'
SET TABLE TBL3 INDEX'775814624 0'
CREATE VIEW OVERLAYSPAN (ID,STREET) AS SELECT DISTINCT ID, NAME FROM OVERLAY AS O, TBL2 as
R WHERE O.ID = R.ID
CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 10
In the java program, I am first removing all entries (1000 entries) from TBL1 and reinserting new entries (1500) in the same table. The program executes normally, but, when I am attempting to re-execute the same program, I am getting the following error.
java.sql.SQLException: error in script file line: 9 S1000 General error
java.lang.NullPointerException in statement [SET TABLE TBL2 INDEX'529105280 529105280 0']
Here is the fill stack trace from the program.
java.sql.SQLException: error in script file line: 9 S1000 General error java.lang.NullPointerException in statement [SET TABLE TBL2 INDEX'529105280 529105280 0']
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at HSQLTesting.main(HSQLTesting.java:98)
Where at line 98, the program is attempting to make a connection with the database.
Connection sqlconnect = DriverManager.getConnection("jdbc:hsqldb:file:C:/birdseyedb/birdseye", "SA", "");
Any idea what's going wrong here?
Thanks in advance.

HSQLDB INSERT Value in a Database

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

Derby SQL Script Bulk Import

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);

Categories