Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
Couldn't able to insert image file in MySQL, Data truncation: Data too long for column 'image' at...
Venkattesh Iyer
Greenhorn
Posts: 6
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello friends,
I dont know what to do, i am tring to insert the image (blob) in to the table but I am getting such error
Data truncation: Data too long for column 'image' at row 1
Here is the code.
import java.sql.*; import java.io.*; public class insertImage { public static void main(String[] args) { System.out.println("Insert Image Example!"); String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName = "mynewdatabase"; String userName = "root"; String password = "admin"; Connection con = null; try{ Class.forName(driverName); con = DriverManager.getConnection(url+dbName,userName,password); Statement st = con.createStatement(); File imgfile = new File("Template.jpg"); FileInputStream fin = new FileInputStream(imgfile); PreparedStatement pre = con.prepareStatement("insert into save_image values(?,?,?)"); pre.setInt(1,100); pre.setString(2,"Template"); pre.setBinaryStream(3,fin,(int)imgfile.length()); // pre.setBinaryStream(3,fin,fin.available()); pre.executeUpdate(); System.out.println("Inserting Successfully!"); pre.close(); con.close(); } catch (Exception e){ System.out.println(e.getMessage()); } } }
Please guide me,
Thanks,
Venkat.
Campbell Ritchie
Marshal
Posts: 79151
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Don't know, but what size image are you passing and what size BLOB did you specify?
Venkattesh Iyer
Greenhorn
Posts: 6
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ya the size of the file was more than tha size of BLOB.
I could solve by using LONGBLOB
Thanks, Venkat
Campbell Ritchie
Marshal
Posts: 79151
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You're welcome
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Struts 2 -Eclipse
Null pointer exception in con.createStatement();
image insert problem
Problem with Uploading Pictures using Jsp
How to store image in JSP from BLOB captured in Oracle
More...