MySQL Workbench saving date one day before (from java console) - java

I'm having a problem with Java console and workbench. Let's start saying I'm using the sql.Date format in java console, and DATE format in the Workbench. I have windows 10 Pro on my laptop, using IntelliJ 2022.3.2 Community edition as IDE, MYSQL with workbench 8.0.32 community edition and mysql-connector-j-8.0.31.
From Java console I want to update my birthdate which is already store in the database. So I take in input the date 1994-06-10, prepare the connection, prepare the query.. at the moment that is getting the query, the value is correct (1994-06-10) but if fills the '?' of my query with 1994-06-09, one day less.
picture here
I printed to make sure the data was stored right, and as you can see it's 1994-06-10, but still the query get filled with one day less. I tried to set the timezone but I think it is right.
Do you guys know how can I solve this issue?
I saw in another topic they said it was fault of the mysql connector older version, so I tried to download the latest and still get the same error.

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.

Oracle query not returning correct number of result

I have a java application which is fetching some records from the oracle database. The query is a simple one
select distinct * from table.
The issue is this query when run from the application does not return all the records. If there are 1000 records in the table then running this application returns different number of records every time. When the query is run directly using pl/sql developer it returns correct number of result.
Strange thing is that exact same code works fine with another Oracle server with exact same version of oracle database (it works fine for lot of other databases too) and the DBA has informed us that the data for both the servers is in sync.
I am not sure where to look for issues. The code does not look faulty. This issue is not reproducible in our lab. I tried to check alert logs but did not find anything. I think that there may be some process which is interfering when we are running the query from the application. Any pointers as to which logs can be analysed on oracle server which may point us in the right direction.
Will enabling audit or transaction logs be helpful?
Oracle version is 12c Enterprise Edition Release 12.1.0.2.0 - 64bit.

How to find errors in large Eclipse program

I've got a rather large program that interacts with a MySQL database. I recently changed the structure of the database considerably, but I thought I had made all of the necessary changes to my program to compensate for those database changes, but clearly I haven't.
I just recently several error messages, the first of which is this:
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
Strangely, though, it doesn't give tell me in which file this error came from (as a typical stacktrace would), let alone on which line number. How can I figure out from where this is coming?
I have a lot of calls to the database in this program, most of which deal with a Timestamp column. And I'm afraid that, while I have been using Eclipse for months now, I still have yet to use its Debug perspective. How can I use that?

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.

Hibernate - different behavior on Linux and Windows

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.

Categories