I am making a software and I want to give an option to add a picture.
I am using Netbeans 7.4 , mySQL server 5.1, And Query Browser 1.2
I want to know how to configure the database and how to develop the feature for adding a picture.
You are able to store images in a mySql db using data types such as LONGBLOB
img LONGBLOB not null
To do this in Java you want to do something like the following to get the byte string of the image:
File image = new File(imageName);
BufferedImage bufferedImage = ImageIO.read(image);
WritableRaster writableRaster = bufferedImage.getRaster();
DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer();
You can then add it to your database using JDBC.
NOTE: Although I have given you the answer on how to do this, I would not recommend implementing it in this way as it is bad practice. Images can get very large and you might find your db filling up very quickly.
Instead, a more efficient solution would be to store the images in directories alongside your code, and store paths to the images in the database as simple text strings.
Related
So I have my location column using Point data type, I'm using Apollo Server and Prisma, and when I use "npx prisma db pull" generates this data type because is not currently supported on Prisma (generated script)
so I say "Ok, I'm using string and I manage how to insert this data type" so I changed to this script, surprise! didn't work enter image description here, try to find any approach to handling MySql Point data type in Prisma but no info at soever, I really appreciate any ideas
You cannot convert it to String and use it as it isn't supported yet. You need to leave it as unsupported and you can only add data via raw queries.
For now, only adding data is supported. You cannot query for it using PrismaClient.
We can query data using Prisma Client, via raw queries as SELECT id, ST_AsText(geom) as geom from training_data where geom has dataType geometry for using Unsupported("geometry").
Currently, I've been assisting someone to convert a site using classic ASP, from using MS Access to MySQL(mainly as a bridge until we get time to do a complete rebuild). The current table uses various protected keywords as column names(Datetime, Date, Order, etc). I'm trying to figure out the proper ways to do a few inserts on these columns. The current code is below:
Set oRSess = Server.CreateObject("ADODB.Recordset")
oRSess.AddNew
oRSess.Fields("Order") = CInt(xyz)
oRSess.Fields("SessionID")
oRSess.Update
Now normally, I'd try to just replace this with a standard SQL insert, but there's lots of code around, that breaks easily. Is there away to add a proper escape character for MySQL to recognize it properly?
What is the best way trying to get a text search function using nhibernate? I have read about NHibernate.Search, but cannot find the library anywhere.
I downloaded the latest NHibernate source code(2.1.2) and compiled it, but i still cannot find NHibernate.Search.
Does anyone have any suggestions? Or any other methods to do text search?
EDIT: Using MySQL database, incase it makes any difference.
NHiberante.Search a separate dll to make Nhiberante and Lucene work together. You have to download and reference it if you want to use it. You might like to read some introduction about Lucene to understand how Nhiberante.Search works.
One of the places where you can get the dll is hornget
If you want to the MySql specific full text search options, there won't be any help from Nhibernate for you to use them.
You can use Expression.Sql but i think it's good idea using mysql stored procedure
Your MySql Stored Procedure :
CREATE PROCEDURE `GetProductsByText`(IN `queryText` VARCHAR(100) CHARSET utf8)
SELECT *
FROM Products
WHERE MATCH(Title, Description) AGAINST (queryText)
Your nhibernate mapping xml file :
<sql-query name="GetProductsByText">
<return class="Product"/>
call `GetProductsByText`( :queryText )
</sql-query>
your c# nhibernate query:
public IList<Product> FindByText (string text)
{
var session = SessionFactory.GetCurrentSession ();
IQuery query = session.GetNamedQuery ("GetProductsByText");
return query.SetString ("queryText", text).List<Product> ();
}
Right I seem to be having a issue inserting a image into a database (don't ask why lol)
If tryed a simple
UPDATE player SET Image = load_file('94.jpg') WHERE id =94;
And had the image directly located from where im running the sql commands from
UPDATE player
SET Image = load_file('C:\Users\***\Documents\databases\Scripts\94.jpg')
WHERE id =94;
I have also tried the above with the full path but when i query the table it shows the Image column of type LargeBlog as empty!
Any ideas????
The file must be on the machine MySQL is installed on.
I have managed to fix it with the use of forward slashes instead of back slashes. So im getting it into the database now... all goood
but i want to do relative paths and as i said ('94.jpg') doesn't work. When its placed my C:\Wamp directory... Which is the same place I put sql scripts when I run them with a simple
source script.sql; <-Notice no path required and it works. So I assumed that MySql default directory was the Wamp Folder
I'm using VSTS Database Edition GDR Version 9.1.31024.02
I've got a project where we will be creating multiple databases with identical schema, on the fly, as customers are added to the system. It's one DB per customer. I thought I should be able to use the deploy script to do this. Unfortunately I always get the full filenames specified on the CREATE DATABASE statement. For example:
CREATE DATABASE [$(DatabaseName)]
ON
PRIMARY(NAME = [targetDBName], FILENAME = N'$(DefaultDataPath)targetDBName.mdf')
LOG ON (NAME = [targetDBName_log], FILENAME = N'$(DefaultDataPath)targetDBName_log.ldf')
GO
I'd expected something more like this
CREATE DATABASE [$(DatabaseName)]
ON
PRIMARY(NAME = [targetDBName], FILENAME = N'$(DefaultDataPath)$(DatabaseName).mdf')
LOG ON (NAME = [targetDBName_log], FILENAME = N'$(DefaultDataPath)$(DatabaseName)_log.ldf')
GO
Or even
CREATE DATABASE [$(DatabaseName)]
I'm not going to be running this on an on-going basis so I'd like to make it as simple as possible, for the next guy. There are a bunch of options for deployment in the project properties, but I can't get this to work the way I'd like.
Any one know how to set this up?
Better late than never, I know how to get the $(DefaultDataPath)$(DatabaseName) file names from your second example.
The SQL you're showing in your first code snippet suggests that you don't have scripts for creating the database files in your VSTS:DB project, perhaps by deliberately excluded them from any schema comparisons you've done. I found it a little counter-intuitive, but the solution is to let VSTS:DB script the MDF and LDF in you development environment, then edit those scripts to use the SQLCMD variables.
In your database project, go to the folder Schema Objects > Database Level Objects > Storage > Files. In there, add these two files:
Database.sqlfile.sql
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [$(DatabaseName)],
FILENAME = '$(DefaultDataPath)$(DatabaseName).mdf',
SIZE = 2304 KB, MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB)
TO FILEGROUP [PRIMARY];
Database_log.sqlfile.sql
ALTER DATABASE [$(DatabaseName)]
ADD LOG FILE (NAME = [$(DatabaseName)_log],
FILENAME = '$(DefaultDataPath)$(DatabaseName)_log.ldf',
SIZE = 1024 KB, MAXSIZE = 2097152 MB, FILEGROWTH = 10 %);
The full database creation script that VSTS:DB, or for that matter VSDBCMD.exe, generates will now use the SQLCMD variables for naming the MDF and LDF files, allowing you to specify them on the command line, or in MSBuild.
We do this using a template database, that we back up, copy, and restore as new customers are brought online. We don't do any of the schema creation with scripts but with a live, empty DB.
Hmm, well it seems that the best answer so far (given the over whelming response) is to edit the file after the fact... Still looking