Hibernate - different behavior on Linux and Windows - java

I've run into a peculiar problem where a hql query is working as expected on Windows but does not on Linux.
Here is the query:
select distinct resource from Resource resource , ResourceOrganization ro
where (resource.active=true) and (resource.published=true) and
((resource.resourcePublic=true) or ((ro.resource.id=resource.id and
ro.organization.id=2) and ((ro.resource.id=resource.id and ro.forever=true) or
(ro.resource.id=resource.id and current_date between ro.startDate and ro.endDate))))
Explanation: I'm fetching resources from database where they are active, published and either public or shared with an organization such that the sharing is either forever or between 2 dates.
I have the same data in both the databases (exported from Linux and imported in Windows).
On windows I get
Result size = 275
and in Linux I get
Result size = 0
I've looked at the data in Linux and I see that I should get non-zero result size.
Windows has Java 1.5 whereas Linux has Java 1.6
Any suggestions on where I should look to address this problem?
Thanks!

In a SQL command-line tool, enter the SQL one phrase at a time and see when the Linux version goes awry. For best results, do the same thing on Windows.
Make sure the SQL generated is the same on windows and linux.
and you're sure they are referring to exactly the same database, and using the same login? (edit - I re-read and saw I have the same data - Are You Suuuuuure?)
and finally, I see this: and ro.organization.id=2 Are you sure the ID is 2 on both systems? You could get lit up by the sequence numbers/autokey IDs being different.

Related

SQL DB2 Database Table automatic export to .csv on WIndows

I am currently training to be an application developer and am in my second month.
Now I got a task that felt impossible for me.
I have also googled since yesterday but did not find anything.
I have to insert the data from a database that I access with SQL Explorer into a .csv file. and save it on my machine
It should work automatically, but for testing it doesn't have to.
I use Eclipse and program with Java, have seen something on the Internet that it works with MySQL, but the DB2 database is connected with the SQL Explorer.
My plan is a solution, programming in java to update everyday the csv thats basically my task
Sorry if it doesn't fit here on Stackoverflow, I'm totally lost because I'm still in the trial period.
Greetings from Germany
IBM Data Server Client and driver types.
The IBM Data Server Driver Package, for example, contains the Command line processor plus utility which can run various db2 commands, statements and scripts including the Db2 EXPORT command.
Usage:
From the OS command line:
clpplus -nw user/password#host:port/database #s1.sql
The contents of the s1.sql file used as a parameter above:
SET ECHO ON;
EXPORT TO "full\path\to\my_file.csv" of del
SELECT *
FROM MYTABLE;
EXIT
You may use whatever valid SELECT statement in the EXPORT command.

Failing to execute MySQL dump on windows 10, IDE is Netbeans 8.2

I have been searching for hours on how to backup the schema for my database through Netbeans 8.2 I just want to backup my work in the event of computer failure. I tried using command line but no resource is up to date yet on how to properly backup for windows 10 and Netbeans 8.2. Any solution would be greatly appreciated.
NetBeans does not offer this feature. You can only grab and recreate the structure of single tables (Under Services / Databases / [your database] / right click on any table). But this does not include any containing data.
Shashanth mentioned already some alternatives where I would like to add HeidiSQL which does an awesome job.
If you want to implement this as a feature in your own application you probably want to call mysqldump from your program (see this question in addition to the thread provided by Shashanth)

Java application and MySQL installation in a single package

How can I pack a Java application and MySQL installation files in a single exe file? Can I install the MySQL files automatically in background (or without any inputs from user)? This is just to simplify the installation procedure.
Java is cross platform, MySQL isn't, so you'd have to create various installers for multiple platforms with different MySQL binaries. If you want to include MySQL source code for non Windows systems, then that's another story... so I assume you want just an installation for Windows.
First of all, get an installation software that you'll feel comfortable with. There is a nice list of free and non free installers on Wikipedia.
Second thing, you can do a silent MySQL installation. How it's done is explained here.
But note that doing a silent MySQL installation without user's permission doesn't sound too good to me, since MySQL isn't exactly lightweight software and you might mess up something if a user already has MySQL somewhere installed.
So, by doing this, you have to be extra careful to check if port 3306 is already up and running (default MySQL port), and other sanity checks to see if there's a possibility of another instance lurking in the background.
It would be better if you at least informed your user that MySQL will be installed. Think about these details, because they might be dealbreakers so some of your users.
Use Java Web Start to launch the application.
JWS offers an ExtensionInstallerService that can be used for installing MySQL. Here is a small demo. of the ExtensionInstallerService.

Getting Manufacturer and Modal # from XP Home with Java or the Command Line

How can I get the Manufacturer and the Modal Number of an XP Home computer? I asked a similar question 3 months ago here. The answers were very helpful, but Windows XP Home Premium Edition does not have wmic or systeminfo. I looked in the registry on a few machines and did not find any consistent patterns.
Do you have any ideas? I'd like to stick with Java and the Command Line.
REG QUERY HKLM\HARDWARE\DESCRIPTION\System\BIOS -v SomeValueName gives you some info about the system, depending on what you use for SomeValueName.
SystemProductName returns the model of my laptop. BaseBoardProduct has the same value, but it's entirely possible that the two will differ on some machines. One of those should give you a model number.
SystemManufacturer and BaseBoardManufacturer have the name of my laptop's manufacturer. Again, the two might differ.
You might be able to get the info by querying HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation, namely the "Model" and "Manufacturer" values. But that looks like info that'd be stored during an OEM install (like when you use Dell's install disc to reinstall Windows on your machine), and may not be present (or may be useless) on home-built systems.
Note, the stuff returned by REG QUERY is in a particular format that you may need to parse. It's not complex, but REG QUERY /? doesn't seem to mention a way to get rid of the headers and the REG_SZ and such that get returned.
(Also note: This is probably obvious to you...but the instant you use Runtime.exec to execute programs to query the Windows registry, you tie yourself to Windows.)
Use Runtime.getRuntime().exec() to execute the appropraite windows command that inspects the registry, capture the output and parse it for the information you need.

Java Updatable Resultset Anomaly with UTF-8 data in English Windows

I am facing a weird problem. I am getting exception when I try to update or delete row in updatable resultset which contains non-english utf-characters. However insert goes fine.
java.sql.SQLException: refreshRow() called on row that has been deleted or had primary key changed.
The weirdest things are:
This error happens only when compiled jar is run in windows
However same jar run in Linux runs fine for same data without problem.
Same project run from within IDE runs also fine in Windows.
Other information in case that will be helpful
OS: Windows XP (English with non-english language support installed)
DB: MySQL, encoding utf8, collation - utf8_general_ci
IDE: Netbeans 6.9.1
JDK: 6 update 23
Connector/J 5.1.15 (Just switch to check if this works but same problem with version 14 too)
Connection string includes: "useUnicode=true" and "characterEncoding=utf8"
Initially thought that IDE has something to do so posted this message in netbeans forum
http://forums.netbeans.org/topic36558.html
Also cross posted in mysql JDBC forums hoping to find some answer
http://forums.mysql.com/read.php?39,408795,408795
but couldn't get any help there.
So far, the problem seems to be Windows. May be this is just minor issue but can't think of any work around.
Need some suggestion
Thanks and regards
Deepak
It seems like your IDE is override the default encoding that you get when you run your application from the command line. If you check the actual JVM arguments the IDE uses (normally available in the output window of your IDE), you will probably see the inclusion of a file-encoding argument, like this:
-Dfile.encoding="UTF-8"
Try to start your application with this JVM argument and see if it makes any difference, and if not - compare the actual encoding used when run from the IDE and on the command line like this:
System.out.println(System.getProperty("file.encoding"));
I had the same problem and solved it. I don't understand why this is happenning but this is caused when your primary key of mysql table is combined. In my database there are many tables that have combined primary key and others that have auto-increment. Likely i noticed that this problem didn't occur in tables with auto-increment primary key.

Categories