0

I'm not sure if this is possible, but I want to be able to store a sentence in a MySQL database after being sent from an Android app. I have a field in my app that allows a user to enter a description (the sentence) and when they press send all of their personal information along with the description is sent to a db. I have all of the personal data sending and receiving, but the sentence is not working. Is there a way to do this? I tried using a BLOB, but it just shows up as [BLOB-4B] in the table. I'm a noob so be gentle. Thanks!

mkyong
  • 12,497
  • 12
  • 37
  • 56
  • 2
    I like how all the personal information goes straight into a database administered by a self-declared "noob". – Niklas B. Mar 22 '12 at 14:34
  • 1
    I'm not familiar with Android but I see no obstacle to storing a `String` in MySQL. Is it possible to use a simple `VARCHAR`? From my understanding, `BLOB`s are generally used for binary data. The `[BLOB-4B]` you're getting is most likely a `toString` value. – James P. Mar 22 '12 at 14:36
  • 1
    Blobs are for binary, you want a [text](http://dev.mysql.com/doc/refman/5.0/en/blob.html) column. – Marcus Adams Mar 22 '12 at 14:36

2 Answers2

1

Use a VARCHAR(num) where num is the maximum length of your sentence.

Help for VARCHAR is here

Here is a question from SO regarding whether to choose Text or Varchar

Community
  • 1
  • 1
Manse
  • 37,765
  • 10
  • 83
  • 108
  • I tried doing that, but if the description is a sentence, the table does not receive any data. If I use one word instead, the database will receive everything. – mkyong Mar 22 '12 at 14:40
  • 2
    Post your code - `varchar` can store strings with spaces in them ! – Manse Mar 22 '12 at 14:41
  • @Alex: How is your sentence stored in Java? Also, how are you mapping it to the MySQL DB? – James P. Mar 22 '12 at 14:44
  • Well I have an EditText that is converted to a string, then I use HttpPost to send it to a PHP script which adds it to the table. I have tried varchar, blob, text, etc., but nothing seems to work. I just tried text, but if I have more than one word, nothing gets added to the db. If I have just one word (for the description, where I want to be able to enter a sentence), everything is added to the db. – mkyong Mar 22 '12 at 14:52
  • This doesn't make much sense. I tried adding another word to the first name field (with a space) and it receives it just fine. They both have the same attributes, except the edittext in the Android app is a text box. Could there be problems converting the content of the text box to a string? – mkyong Mar 22 '12 at 14:59
  • @Alex again - post your Java code ... without that we are guessing ! – Manse Mar 22 '12 at 15:36
0

Use the TEXT datatype. VARCHAR, CLOB (character large object), etc all have TEXT affinity in sqlite v3 (since you have the question tagged with Android).

Dhruv Gairola
  • 9,102
  • 5
  • 39
  • 43