开发者

Insert Audio File Into Mysql Database

How can we insert audio files in to MYSQL Database using JAVA DATABASE CONNECTIVITY connectivity

For inserting image we use

 psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,photo) "
                            + "values(?,?)");

            psmnt.setLong(1, userId);

            fis = new FileInputStream(photoFile);
            psmnt.setBinaryStream(2, (InputStream) fis, (int) (photoFile
                    .length()));
            /*
             * executeUpdate() method execute specified sql query. Here this
             * query insert data and image from specified address.
             */
            int s = psmnt.executeU开发者_JAVA技巧pdate();

To insert an audio file in 3gp format , what will be the code using JDBC


The code should be exactly the same: you will need to make sure your audio file is small enough to fit into the column (mediumblob is 16MBits or there abouts if I recall correctly. The database doesn't care if its audio or image data.

For the sake of discussion:

psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,audiofile) "
                            + "values(?,?)");

            psmnt.setLong(1, userId);

            fis = new FileInputStream(audioFile);
            psmnt.setBinaryStream(2, (InputStream) fis, (int) (audioFile
                    .length()));
            /*
             * executeUpdate() method execute specified sql query. Here this
             * query insert data and image from specified address.
             */
            int s = psmnt.executeUpdate();

Seems fair?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜