|
|
| JSP-Mysql |
Expert:Jagadeesh
Hello friends,
Anyone send me the way how to store image in mysql database from a jsp page. |
| Answers |
Hi friend,
Code to insert image in mysql Using Jsp :
<%@ page import="java.sql.*,java.io.*" %>
<% String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName = "hibernatetutorial"; String userName = "root"; String password = "root"; Connection con = null; try{ Class.forName(driverName); con = DriverManager.getConnection(url+dbName,userName,password); Statement st = con.createStatement(); File imgfile = new File("c:\\EricssonT29.jpg"); FileInputStream fin = new FileInputStream(imgfile); PreparedStatement pre = con.prepareStatement("insert into Image (image) values(?)"); pre.setBinaryStream(1,fin,(int)imgfile.length()); pre.executeUpdate(); out.println("Inserting Successfully!"); pre.close(); con.close(); } catch (Exception e){ System.out.println(e.getMessage()); } %>
For more information on JSP visit to :
http://www.roseindia.net/jsp
Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|