How to show image in table using mysql command line - mysql

I have tried to show photo in MySQL command line, but always unable to do. Although I can retrieve photo using JDBC.
I am beginner to learn JDBC using MySQL, so, please help me by giving answer.mysql code are given below
create database image;
use image;
create table imgtable(photo,BLOB);
insert into imgtable(photo) values(LOAD_FILE('D:\\pic.png'));
select *from imgtable;
I cannot find storage photo in imgtable, only show garbage. But why it occur like this, actually is it not possible to show in table. Please suggest a way.
Thank you.

Blob data types in mysql store the information in encoded form. Hence you can only see the result in garbage form which is not actually garbage but your image in encoded form.

Related

mysql query will only return results if i hard code the text in the database

I have a MYSQL database with a query. The query only works if I manually type in the data with MYSQL Admin or with the following statement $sn="x-xxx"; It will not return results if i pass $sn to the database from a form even though the $sn get inserted into the database just fine. I can look at the database and see that it's there. Not sure if why the query would only pull down the records I manually imputed.
Thanks for the help guys. I found that by passing the variable from page to page that a space was being added to the variable. I used:
$sn=preg_replace('/\s+/', '', $sn); and var_dump($sn); to strip the space and to check what was being posed. Wow 5 full days trying to find this. Thanks to everybody who answered.

help me restore a database

I have a database backup that I'm trying to load so that I can extract some historical averages. I think it was a MySQL database, but with some syntax adjustments I was able to create the one and only table I need in Oracle 11g. However, I'm having problems with the INSERT INTO portion of the backup. Basically, some of these text fields were taken directly from fields on our website, and whenever users entered an apostrophe, it messes up everything that follows. Finding all instances of this would take a very long time...
Is there any way to handle this?
Also, all the text in SQL Developer runs horizontally on 2 or 3 rows. Is there any way to fix that? It makes for a lot of side-scrolling instead of vertical scrolling.
Use phpMyAdmin to reload the database into mySQL.

Create and use data tables in netbeans

I have a table with:
vegetable name -- calcium contents -- Potassium contents -- vitamins -- fibers-- price (etc)
Let's say there are 5 entries (rows) in the table and I have to initially feed the data manually, like a first one time data feeding.
My requirement/problem is:
On a GUI when I select a vegetable name from a drop down menu I should get the contents displayed and then all of them should get added to get final score except the 'price'.
On the GUI if I select the 'vegetable name' and any one of the other 'property' (like 'fibers') then only that value should be displayed. e.g query-- spinach, fiber ? answer spinach-fiber = 20 unit., or spinach-vitamins = 40units etc.
I also want help in what type of database I should use here and how to populate the data for accessing it in the program later on. I believe its a simple data table of small size so what is the most efficient way of doing this?
Specific help with code will be of great help as I am absolutely new to java and netbeans.
Also, can I have a separate GUI for adding/appending further data from user in the same table? If yes, how is it done please?
I am using Netbeans 7.1.2.
After some search I got info about MySQL datatables in netbeans. (http://netbeans.org/kb/docs/ide/java-db.html)
I have created and made entries in the table but do not know how to access them for my questions 1 and 2 above. Also not sure if it is the right data table that I should be using for such simple use.
Seems like you need to learn about JDBC first. Just to clarify connecting to a database inside the IDE is generally used for more development/administrative type duties and you WONT be using it in your Swing program.
So for example you need to load a set of test data to test a function you would typically use either the MySQL workbench or load it via the IDE. However you will not connect this way when you run a program.
What you need to learn is how to connect to a database from a front end, how to execute a query and how to display the query. At this point I would suggest getting a couple of books on JDBC or even doing a google search for JDBC introduction tutorials.
Get to learn JDBC without thinking too much about the front end. Do a couple of examples and then once you are familiar with JDBC then work on the front end.
You might want to spend time on learning basic SQL as well as this will be needed to properly query your database. I am assuming you have not done any SQL.
Here is a reasonably good link to a site with information that you might want to use http://infolab.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html
Just remember the IDE(Netbeans) basically uses JDBC to allow you to connect and manipulate data. So while it is based on JDBC the IDE database explorer is NOT the tool you will be using when programming your swing interface.

MySQL 5.5 LONGBLOB Column Data too long for column 'x' at row 1

I have a column in my MySQL database that stores images as a byte array.
I am trying to update a row to insert a new image. The new image is 163K, and when I convert it to a byte[], the number of elements in the array is 167092. When I run the stored procedure that does the update, I get an error "Data too long for column 'x' at row 1. I already have an existing image in the database that has 8844 byte[] elements when converted.
The column datatype is LONGBLOB. From my understanding, I should have appox 4Gb to work with.
I have tried updating my my.ini file to make the MAX_ALLOWED_PACKETS=16M and I even tried 100M.
I am using the MySQL .NET Connector libraries to execute my stored procedures.
Does anyone have any ideas on how to fix this issue? I know I could store the image paths instead of storing the images directly into the database. But I would like to know how to solve my current issue and still store the images in the database first before trying to change my approach.
I've had exactly the same problem...
In my case I was passing the LONGBLOB via a TEXT parameter since I wanted to use CONCAT inside the stored procedure in order to create dynamic SQL.
The solution was simply to change TEXT into LONGTEXT. That's it :)
That really took some time to figure out...
Hope I could help even after almost three years.

Updating a Part of string in MySQL

I want to know if it is possible to update a small part of string in MySQL. For example, you have 100 pages stored in MySQL table. In each page there is a link which labeled at "2010 Updates". You want to change the Label to "2011 Updates". Can we do that using MySQL Update statement???
Thank you so much
You could try this video http://www.sebastiansulinski.co.uk/tutorials/play/261
I would just do a select statement, and looping through it, running a regex on each row, then updating said row; but the video gives you another option.