Results 1 to 10 of 10
  1. #1
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Exclamation how to set NVarchar data type

    hi-
    im using netbeans 6.8 and i want to create a column in my table that in my data base with the data type of Nvarchar. im doing this because according to what i understood this is the way to store Unicode strings in a DB.
    does any one have any idea on how to do this?
    +(stupid question) im using derby: does it support nvarchar?

    thanks
    Edi

  2. #2
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    any body?:confused::confused:

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Which table are you referring here? Table is database or JTable you may be used in your application?

    Or do you want to create a table in a database dynamically?

    Can you clear-up me. I'm not much clear what you are saying.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by edi.gotieb View Post
    hi-
    im using netbeans 6.8 and i want to create a column in my table that in my data base with the data type of Nvarchar. im doing this because according to what i understood this is the way to store Unicode strings in a DB.
    does any one have any idea on how to do this?
    +(stupid question) im using derby: does it support nvarchar?
    You can use the "varchar(<number>)" type where <number> is the maximum number of characters allowed per column value. This type is very well capable of storing Unicode strings (a la Java's String type). This is all in your manuals that come with your JavaDB (Derby) distribution.

    kind regards,

    Jos

  5. #5
    edi.gotieb is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    from what i read i need to use the nvarchar type.
    + i tried using the varchar and after i insert a unicode string then read it, it
    appears as squares(i.e undefined characters).
    Which table are you referring here?
    I am referring to a database table.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by edi.gotieb View Post
    from what i read i need to use the nvarchar type.
    + i tried using the varchar and after i insert a unicode string then read it, it
    appears as squares(i.e undefined characters).
    Most likely that's just a font problem. Try another font; the varchar type is very well capable of storing Unicode Strings.

    kind regards,

    Jos

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    the varchar type is very well capable of storing Unicode Strings.
    In database? I don't think so.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Eranga View Post
    In database? I don't think so.
    Sigh, this is straight from Derby's reference manual:

    Quote Originally Posted by Derby
    VARCHAR data type
    VARCHAR provides for variable-length storage of strings.

    Syntax
    { VARCHAR | CHAR VARYING | CHARACTER VARYING }(length)
    length is an unsigned integer constant, and it must not be greater than the constraint of the integer used to specify the length, the value java.lang.Integer.MAX_VALUE.

    The maximum length for a VARCHAR string is 32,672 characters.

    Corresponding compile-time Java type
    java.lang.String


    JDBC metadata type (java.sql.Types)
    VARCHAR

    Derby does not pad a VARCHAR value whose length is less than specified. Derby truncates spaces from a string value when a length greater than the VARCHAR expected is provided. Characters other than spaces are not truncated, and instead cause an exception to be raised. When comparison boolean operators are applied to VARCHARs, the lengths of the operands are not altered, and spaces at the end of the values are ignored.

    When CHARs and VARCHARs are mixed in expressions, the shorter value is padded with spaces to the length of the longer value.

    The type of a string constant is CHAR, not VARCHAR
    kind regards,

    Jos

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    I would assume it's the same (or similar) to Oracle.
    The db charset needs to be the right type, that's all.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    I would assume it's the same (or similar) to Oracle.
    The db charset needs to be the right type, that's all.
    Nah, Oracle is a bit behind and it's still fiddling with the varchar2 type. JavaDB/Derby is written in Java and (therefor?) uses the same data types as Java do. The ANSI SQL standards also allow for all unicode characters to be efficiently stored. Those ANSI SQL standards are a bit too 'open', i.e. different vendors do different things and they're all compliant ;-)

    kind regards,

    Jos

Similar Threads

  1. Primitive data type and class
    By Roselicious in forum New To Java
    Replies: 3
    Last Post: 04-19-2010, 04:27 PM
  2. JNI accessing non primitive data type
    By H_P in forum Advanced Java
    Replies: 1
    Last Post: 04-14-2010, 06:43 AM
  3. Error if someone enters the wrong data type
    By lithium002 in forum New To Java
    Replies: 43
    Last Post: 11-16-2009, 05:41 PM
  4. Problem with nvarchar and SQL Server
    By gadsagiv in forum JDBC
    Replies: 0
    Last Post: 09-09-2009, 09:18 AM
  5. sychronized data type
    By java girl in forum Threads and Synchronization
    Replies: 3
    Last Post: 02-13-2009, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •