MySQL Collation

Συζητήσεις για γλώσσες προγραμματισμού και θέματα σχετικά με προγραμματισμό.
Post Reply
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

MySQL Collation

Post by PaP » Fri Dec 30, 2005 2:12 pm

Χρόνια πολλά σε όλους καταρχήν.

Το πρόβλημα μου είναι ότι θέλω να επεργάστω μέσω Java κείμενο από ένα forum. To collation της βάσης είναι latin1_general και φυσικά τα ελληνικά φαίνονται σαν κάτι τέτοιο ας πούμε åñãáóéá αλλά όταν από τον browser βάλει ς encoding ISO-8859-7 όλα καλά. Το θέμα είναι ότι όταν συνδέομαι στη βάση με Java δεν μπορώ με τίποτα να φτιάξω ένα string με αυτό το encoding και να μπορώ να επεξεργαστώ τα ελληνικά...

Any ideas ?
User avatar
Einherjar
Venus Project Founder
Venus Project Founder
Posts: 3751
Joined: Tue Jan 27, 2004 4:42 pm
Academic status: Alumnus/a
Gender:
Location: Washington DC, USA
Contact:

Post by Einherjar » Fri Dec 30, 2005 2:58 pm

μπορείς να φτιάξεις ένα string με το encoding που θες χρησιμοποιώντας έναν συγκεκριμένο κατασκευαστή που λέει:

Code: Select all

String

public String(byte[] bytes,
              String charsetName)
       throws UnsupportedEncodingException

    Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

    The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.

Parameters:
    bytes - the bytes to be decoded into characters
    charsetName - the name of a supported charset 
Throws:
    UnsupportedEncodingException - If the named charset is not supported
Since:
    JDK1.1 
Αν θες στη συνέχεια να αλλάξεις το encoding μπορείς να κάνεις

Code: Select all

byte[] result = str.getBytes(targetEncoding);
Σου κάνει αυτό?
[Better to understand a little than to misunderstand a lot]
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Post by PaP » Fri Dec 30, 2005 4:22 pm

Το δοκίμασα αλλά δε...
Το πρόβλημα είνια ότι τα ελληνικά στη βάση βρίσκονται σε latin1_general_ci. Βέβαια ο browser τα δείχνει κανονικότατα όταν είναι σε ISO-8859-7 και επίσης όταν ποστάρεις γράφει καλά. Αλλά αν προσπαθήσω από Java δεν γίνεται τίποτα. Νομίζω στη Java είναι ISO8859_7 ?
User avatar
Einherjar
Venus Project Founder
Venus Project Founder
Posts: 3751
Joined: Tue Jan 27, 2004 4:42 pm
Academic status: Alumnus/a
Gender:
Location: Washington DC, USA
Contact:

Post by Einherjar » Fri Dec 30, 2005 5:54 pm

βασικά λέω να τα πάρεις σαν 8859-1 και να τα μετατρέψεις σε 8859-7. Δεν είμαι σίγουρος για το αν θα δουλέψει αλλά give it a try.
Νομίζω στη Java είναι ISO8859_7 ?
yep
[Better to understand a little than to misunderstand a lot]
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Post by PaP » Fri Dec 30, 2005 6:47 pm

Ναι βρήκα το λάθος. Παίζει αυτό που λες. Το πρόβλημα ήταν ότι το πεδίο και ο πίνακας είχαν διαφορετικό collation.
Πάντως Java 1.5 >> Java 1.4
User avatar
Swtos
Kilobyte level
Kilobyte level
Posts: 309
Joined: Mon Apr 18, 2005 4:52 pm
Academic status: MSc
Gender:
Location: Δ.Π

Post by Swtos » Mon Jul 24, 2006 9:06 pm

Καλησπέρα κ απο μένα!

Έχω μια βάση MySQL με collation utf8_general_ci και προσπαθώ να φτιαξω ένα interface(σε PHP αν εχει σημασία) που να επικοινωνει με αυτη. Η βαση εχει ελληνικά μεσα τα οποία όμως μου τα εμφανίζει ως ??????. Εχω δοκιμασει και το ISO-8859-7 αλλα τιποτα! Καμία ιδέα;
-My father made him an offer he couldnt refuse
-What was that?
-Luca Brasi held a gun to his head and my father assured him that either his brain or his signature would be on the contract

-The Godfather
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Post by PaP » Tue Jul 25, 2006 12:10 am

Θα πρέπει η HTML που παράγεις αν έχει εντολή για utf-8 collation

Δηλαδή:

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
User avatar
Swtos
Kilobyte level
Kilobyte level
Posts: 309
Joined: Mon Apr 18, 2005 4:52 pm
Academic status: MSc
Gender:
Location: Δ.Π

Post by Swtos » Tue Jul 25, 2006 12:17 am

Το ξέρω, το δοκιμασα και αυτό αλλα παλι ???? μου βγαζει. Ευχαριστώ παντως!
-My father made him an offer he couldnt refuse
-What was that?
-Luca Brasi held a gun to his head and my father assured him that either his brain or his signature would be on the contract

-The Godfather
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Post by PaP » Tue Jul 25, 2006 10:00 am

Υπάρχουν κι άλλα θέματα τότε...
Το collation της σύνδεσης της βάσης αλλά και το collation των πεδίων με αυτά του πίνακα παίζει να είναι διαφορετικά
Post Reply

Return to “Προγραμματισμός”