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.
Related
I'm working on a legacy project where we use Java 6 with Spring, Grails, etc.
The problem I'm running into, is that I have an file upload form, where we support support German filenames.
In this case I have a file named something with "für" and I'm having difficulties with that now.
I have tried converting it to unicode to see if that solved the problem but I am now able to see why there's a problem.
On Mac Chrome, it produces U+308 while on Mac Safari it produces U+00FC, with Safari it works and inserts correctly in MySQL, the other one fails.
The error from MySQL:
#1366 - Incorrect string value: '\xCC\x88r' for column `name` at row 1
When I try running this code:
UPDATE `X` SET `name` = 'für' WHERE `skabelon`.`id` = 1302
Why is there a difference and how can I fix it so it'll work with Chrome on Mac? Windows and Ubuntu Chrome works flawless.
UPDATE
It's now working after Normalizing the string.
It worked after I put it through normalizing in Java. Never knew that I needed that before now.
I used the Normalizer from java.text
Normalizer.normalize("String", Normalizer.Form.NFC)
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)
I found that Derby database is installed with the jdk automatically. I wanted to use bu I encountered a problem for which I could not find the solution in google.
I have a russian version of windows. Derby seems to be installed correctly, but when i start the database itself or sysinfo - it gives me out some info but in some unknown symbols - actually its a mess in cyrillic symbols instead of plain english. When i try to create a database - it throws an exception so I cant connect, but I cant read the message because of the mess in the symbols.
Has anyone had the same problem?
If I dont find the solution, how can I uninstall Derby from the jdk-release and install it locally into another directory?
You can install derby separately by going to http://db.apache.org/derby and downloading the JAR files and adding it to your project class path. I always do this instead of using the default derby that comes with the JDK.
by the way, if you do this and still get those weird symbols, your problem might be elsewhere. Hope you solve this, derby is a cool embedded db :)
You can also use derby as a filesystem DB. Download from here Then in your code, you need to change driver name and connection string accordingly.
For in memory
driver=org.apache.derby.jdbc.EmbeddedDriver
url=jdbc:derby:memory:myDB;create=true
For fileSystem ,
driver=org.apache.derby.jdbc.ClientDriver
url=jdbc:derby://localhost:1527/schema_name;create=true
My current task is to migrate a remote database to a localhost database. Everything seems fine up to now. The problem is when I'm checking whether the data are the same, data in my localhost weren't copied correctly. Japanese, Chinese and Arabic Characters were all question marks with boxes. I've searched the net and I've come to understand that it has something to do with the encoding scheme. I've checked the syntax, but none of them seem to work for me.
Can you provide me how to do it using JAVA?
NOTE: I seem to have a problem altering the database, (i think i don't have the permission ) so i would like to know if setting cssid in the tablespace is applicable.
When I once had trouble with encodings in DBs it was of a missing param in the commandline of my app:
java ... -Dfile.encoding=UTF-8 ...
The problem could come from the database codeset which permits to define the type of characters you are entering. However, it cannot be canged once the database was created.
Also, a normal column could not support graphic characters. Probably, you need to use a column that support graphic characters like: Graphic, vargraphic or dbclob
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.