Oracle 5.0 Reference Manual page 1932

Table of Contents

Advertisement

Data stored in a
code. There are no special requirements for using Connector/Net with
Simple code examples will be presented within this section, and a full sample application can be found
in the
Samples
20.2.5.10.1. Preparing the MySQL Server
The first step is using MySQL with
table to be accessed. In my file tables, I usually have four columns: an
of appropriate size
column that stores the file name, an
and a
MEDIUMBLOB
definition:
CREATE TABLE file(
file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
file_name VARCHAR(64) NOT NULL,
file_size MEDIUMINT UNSIGNED NOT NULL,
file MEDIUMBLOB NOT NULL);
After creating a table, you might need to modify the
variable determines how large of a packet (that is, a single row) can be sent to the MySQL server. By
default, the server only accepts a maximum size of 1MB from the client application. If you intend to
exceed 1MB in your file transfers, increase this number.
The
max_allowed_packet
Administration screen. Adjust the Maximum permitted option in the Data / Memory size section of the
Networking tab to an appropriate setting. After adjusting the value, click the Apply button and restart
the server using the
value directly in the
max_allowed_packet=xxM;
Try to be conservative when setting max_allowed_packet, as transfers of BLOB data can take some
time to complete. Try to set a value that will be adequate for your intended use and increase the value
if necessary.
20.2.5.10.2. Writing a File to the Database
To write a file to a database, we need to convert the file to a byte array, then use the byte array as a
parameter to an
The following code opens a file using a FileStream object, reads it into a byte array, and inserts it into
the
table:
file
Visual Basic Example
Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand
Dim SQL As String
Dim FileSize As UInt32
Dim rawData() As Byte
Dim fs As FileStream
conn.ConnectionString = "server=127.0.0.1;" _
& "uid=root;" _
& "pwd=12345;" _
& "database=test"
Try
fs = New FileStream("c:\image.png", FileMode.Open, FileAccess.Read)
FileSize = fs.Length
Connector/Net Programming
column can be accessed using Connector/Net and manipulated using client-side
BLOB
directory of the Connector/Net installation.
BLOB
(UNSIGNED
SMALLINT) to serve as a primary key to identify the file, a
UNSIGNED MEDIUMINT
column that stores the file itself. For this example, I will use the following table
option can be modified using the MySQL Workbench Server
Startup / Shutdown
file (add a line that reads max_allowed_packet=xxM), or use the
my.cnf
syntax from within MySQL.
query.
INSERT
data is to configure the server. Let's start by creating a
column that stores the size of the file,
max_allowed_packet
screen of MySQL Workbench. You can also adjust this
1912
data.
BLOB
column
AUTO_INCREMENT
VARCHAR
system variable. This
SET

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents