H2 database with corrupted table - java

We have an H2 database with what looks to be a corrupted table. Using the H2 web console, we are able to run SELECT * queries on all the tables except one. For this one table, TBL_TRANSACTION, we get the error result:
SELECT * FROM TBL_TRANSACTION;
General error: "java.nio.BufferUnderflowException"; SQL statement:
SELECT * FROM TBL_TRANSACTION [50000-190] HY000/50000
When we run the H2 Recover tool, we get the following:
java -cp h2-1.4.190.jar org.h2.tools.Recover
Error: java.nio.BufferUnderflowException
The Recover tool does generate the h2.sql and the mv.txt file. However, after all the CREATE and INSERT statements, the h2.sql ends with
// error: java.nio.BufferUnderflowException
Running RunScript against this h2.sql file does recover a part of the corrupted table, but only a very small part (only up to the part where the BufferUnderFlowException occurred.)
Questions:
What could have happened to cause this corruption?
What steps can we take to recover the data?
Thanks in advance.

Related

Hibernate unable to retrieve resultSet in production environment

I'm having trouble identifying the issue with Hibernate where Hibernate throws persistence exception.
I've include a screenshot of the code.Sorry regarding the censoring. Source Code
Added logs as per Christian's suggestion. Application logs
The following are findings which I've done to identify the problem
Production
Application logs show the following error (javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not extract
ResultSet Application exception overridden by commit exception) Where
it manages to enter the DAO function but it doesn't show the Hibernate
query in logs,also fail to exit function. Ran the same source code
query in production using SQL and it returned expected results.
Just to clarify: There's another DAO function which uses the same
tables and it manages to display correctly on production so I doubt it would be a table grant issue
Development
Records from the query display correctly on front - end when queried
data is present, logs show that it manages to enter and exit the DAO
function with the query displayed. No error even when there are no
results in database table to retrieve (Logs show the Hibernate query, front-end has no results)
You are not showing the exact error details so it's hard to help. I guess you are setting some parameter to null maybe which Oracle can't handle or maybe one of the functions you are using can't handle the data. The error details you are logging should help you get to the bottom of this.

MySQL Dump File is Excluding almost all Insert Statements

I created a DB using MySQL, the script to create this database creates 4 tables and has multiple inserts satetments for each table.
After I run the script the tables are created and the insert statements run without an error.
I run a Java app that also uses the DB and the app runs perfectly and I can see that the insert statements have been added.
However when I create a dump file via the Windows CMD line the sql file that is generated by the CMD Command only contains one insert statement for
each table. Why does this happen ?
It's possible to use a bulk insert that inserts all rows from one table in one statement (multiple value lists will appear after the insert statement). Depending on how large your tables are, or how many indexes and foreign keys you have, this can be very efficient when dumping and restoring.
I expect that the windows cmd line is invoking this option (--extended-insert or -e) by default, whereas whatever you used to create the initial dump was using single row inserts.
Can you check the output from the windows cmd line dump carefully, or perhaps paste an excerpt from it here?
Alternatively if you just run
mysqldump your-database-name > your-dumpfile-name.sql
(ie: no flags or options)
Then you should get multiple insert statements.

JasperServer Error - Unable to get next record

I have a very simple report that runs perfectly on in iReports (4.5.0) on my workstation. When I upload it JasperServer CE (4.5.0) I get the following error.
1 - Unable to get next record.
java.lang.Exception: 1 - Unable to get next record.
at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:403)
at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:320)
at com.jaspersoft.ireport.jasperserver.ReportRunner.run(ReportRunner.java:70)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
There are other much more complex queries and reports that are running on the JasperServer without problem. The database system is Basis/Pro5 running BBJ (Business Basic Java). I am connected to the database in iReports and JasperServer using the same native JDBC Basis driver (BBjJDBS.jar). JasperServer is running on the same RHEL box as the BBj database. Jasper server is installed as a bundle using both the built in DB and Tomcat. No other known conflicts exist.
The following single table query is designed to get the sum totals of a transaction for a given month. The report has one detail section which just prints the query output.
SELECT
Month(INHI.TRANSACTION_DATE) AS TransMonth,
admin.INHI.ITEM_ID,
admin.INHI.TRANSACTION_TYPE,
SUM(admin.INHI.TRANS_QUANTITY) as TransQty
FROM
admin.INHI
WHERE
admin.INHI.ITEM_ID = 'R-CBSH-3300'
AND (
admin.INHI.TRANSACTION_TYPE = 'B2'
OR admin.INHI.TRANSACTION_TYPE = 'P1')
AND admin.INHI.TRANSACTION_DATE BETWEEN '2012-01-01' AND '2012-03-31'
GROUP BY
Month(INHI.TRANSACTION_DATE),
admin.INHI.ITEM_ID,
admin.INHI.TRANSACTION_TYPE
Order By
admin.INHI.TRANSACTION_TYPE
I have looked all over to try and find additional trouble shooting tips and have ran out of options to try. Any guidance is greatly appreciated.
In my case I was able to get an extended error from the JasperServer web interface which lead me to an Date/Time issue. The crux of the whole problem was the "Order By" clause. Once I removed the order by the query worked fine.
You can also get this error if you pass a closed result set as the data source for the report.
In my case I passed the JasperReportBuilder object around and somewhere I (prematurely) closed the Connection object that the result set was bound to.

Building an MSSQL database with ColdFusion or Java from an ".sql" file?

I have a .sql file that was created using the MS SQL Management Studio Script Wizard. It contains the entire database schema including views, stored procedures, tables, indexes, etc.
I’m looking for a way to automate the process of creating the database with ColdFusion or Java or even .NET.
I’ve tried using CFQUERY but it throws all kinds of errors with the .sql file.
I’ve tried using ANT with sqljdbc4.jar but it also fails on the first line with a “[sql] Failed to execute: BEGIN TRAN” com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ''.
I highly doubt you can use the scripts generated by the wizard outside of an MS tool. The wizard makes copious use of GO which is not standard T-SQL. Also, commands like CREATE PROCEDURE need to be the first statement within the batch. To run the wizard scripts, you need to use an MS tool like sqlcmd.exe. With the correct permissions, you should be able to run sqlcmd.exe from <cfexecute>.
You should be able to execute all the SQL within a <cfquery assuming you have the appropriate permissions.
We generate all our databases like this with CREATES etc in a ColdFusion <cfquery
Do you have the appropriate permissions, what errors are you getting.
If you're using ORM, you may set this.ormsettings.sqlscript to point to your .sql file in Application.cfc and it'll be run on ORMReload() when this.ormsettings.dbcreate is set to dropcreate.
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSED380324-6CBE-47cb-9E5E-26B66ACA9E81.html
Good luck

HSQLDB - hiding database structure/contents from users

I'm considering using HSQLDB version 1.8.x in a desktop app for storing local data. From what I can see, the database is stored on disk as a number of SQL statements to create the tables, insert the data, etc.
Is there a simple way I can hide this from users? I'm don't necessarily need it to be completely encrypted, etc - I'd just like to prevent the casual user from simply opening the file and seeing the structure of the database.
You could embed your database files within a jar file and connect to them using the notation:
jdbc:hsqldb:res:<path in jar>
Check out the Advanced Topics section of the HSQLDB guide for more information on this. However, I've never tried it so am not 100% sure it will work ...
The solution I've gone with for now is to call:
db.update("SET SCRIPTFORMAT COMPRESSED;");
to store the .script file in a human-unreadable form and:
db.update("SET PASSWORD password;");
to prevent more savvy users from opening the DB using their own HSQLDB client.
Unfortunately I was not able to execute below command
db.update("SET scriptformat COMPRESSED");
And was getting this error
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SCRIPTFORMAT
This error solved with this command
db.update("SET FILES SCRIPT FORMAT COMPRESSED");
I am using HSQLDB 2.3.3

Categories

Resources