How to get hash value of a text saved in a database - mysql

I'm working with a web application and I want to get the hash value of the text which is saved in a MySQL database table,I'm new to this field and I'm using Spring-MVC for the web application,can any one please help me?

By hash, are you talking about any specific hashing function? A common one that you can use is md5, which mysql supports:
select md5(some_column) from some_table;
Here's a link to the reference: Mysql Reference/Encryption Functions

Related

Hashing data at database layer or application layer

I will take example of my case . I am using PostgreSql .I have gone through postgresql crypt() function documentation .
This function is provided as extension for postgresql .
If i migrate my data to another database by different vendor , Will the passwords still be evaluated properly or not ?.
If i try to compare the the hash generated in postgresql with hashing utilites provided by mysql/mongodb using same source string will it evaluate to be equal or not
According to docs, crypt()
Calculates a crypt(3)-style hash of password. When storing a new
password, you need to use gen_salt() to generate a new salt value. To
check a password, pass the stored hash value as salt, and test whether
the result matches the stored value.
It means if you migrate your data to another database (if stored hash value is part of your data of course), the result of comparison will not depend on the system.
Can you move up the encryption/decryption to the application level? In that case, you can migrate data as encrypted and other database vendor don't need to worry would consider them as normal data?
Another option is to encrypt disk level instead of applying encryption at a database level.
After going through lot of posts it came to me that encrypting at application layer is better . like for example to encrypt passwords in java, we can use jBcrypt library .

What is the best way to store a pretty large JSON object in MySQL

I'm building a Laravel app the core features are driven with rather large JSON objects. (the largest ones are between 1000-1500 lines).
I know there are better data base choices than MySQL for storing files and blocks of data, but for various reasons I will need to use MySQL for the application.
So my question is, how to I store my JSON objects most effective in MySQL? I will not need to do any queries on the column that holds the data, there will be other columns for identifying it. Something like this:
id, title, created-at, updated-at, JSON-blobthingy
Any ideas?
You could use the JSON data type if you have MySQL version 5.7.8 or above.
You could store the JSON file on the server, and simply reference its location via MySQL.
You could use also one of the TEXT types.
The best answer i can give is to use MySQL 5.7. On this version the new column type JSON are supported. Which handles large JSON very well (obviously).
https://dev.mysql.com/doc/refman/5.7/en/json.html
You could compress the data before inserting it if you don't need it searchable. I'm using the 'zlib' library for that
Simply, you can use the type longblob which can handle up to 4GB of data for the column holding the large JSON object where you can insert, update, and read this column normally as if it is text or anything else!

How to show image in table using mysql command line

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.

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.

Accessing Return Values from Oracle Text using Oracle Enhanced Adapter

I am building a Rails application. The application uses MySql as the main database and the oracle-enhanced adapter to access a legacy Oracle database that contains documents the application needs to search. With the oracle-enhanced adapter, I want to use the existing Oracle Text index to search for documents. My Rails application can connect to the Oracle db and the scaffolding attached to my model is working fine.
What I need now what exactly is returned from oracle-enhanced adapter when it searches an Oracle Text index? Additionally, I need to know how to access the returned values. For example, when I search the Oracle Index using the oracle-enhanced adapter syntax " Post.contains(:title, 'word')" does the returned information include document id,
document name, document date, words found in the search, and any type
document ranking or document score? I need any and all that information to update a results table in my MySql database. Can someone point me to where I
can get that information?
Answer provided in oracle_enhanced discussion group
https://groups.google.com/d/topic/oracle-enhanced/6Y52ihs9wtQ/discussion