File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Store char[] as column type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Store char[] as column type" Watch "Store char[] as column type" New topic

Store char[] as column type

Preeti Yarla
Ranch Hand

Joined: Sep 08, 2007
Posts: 69
JDBC beginner

Hi, I am trying to get password from Java Password Field and store it in a table in MySQL database. This password is a char[] and I do not know how to store char[] as a column type in MySQL. How do we store arrays in database?


David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You can convert it to a String (I believe using new String, but you may need also the character set)
Preeti Yarla
Ranch Hand

Joined: Sep 08, 2007
Posts: 69
That's what I did. Convert the char[] to a string with new String(char[]) and then store it as a varchar in database. Thanks David. But can we store it as an array (as object?). MySQL documentation shows the matching column type for byte[] but not for other arrays.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
I looked through the index for the MySQL 5.0 handbook, and it doesn't say anything about arrays, so I would presume you can't store arrays as such. Maybe as a blob? Don't know.
Preeti Yarla
Ranch Hand

Joined: Sep 08, 2007
Posts: 69
This is the link I referred to for Java - MySQL mapping

I misunderstood. It does not show a type for byte[] either.
[ July 07, 2008: Message edited by: Preeti Yarla ]
I agree. Here's the link:
subject: Store char[] as column type
It's not a secret anymore!