How can I insert image URL in database using java stored procedure in MySQL database?
Asked
Active
Viewed 872 times
1
-
there is a chance to store fakepaths in database due to security issues while uploading images from local system, of course you can check once about query at: http://stackoverflow.com/questions/8445648/how-to-store-only-image-path-url-in-database-rather-than-image-itself – Dhana Mar 11 '16 at 09:18
1 Answers
0
First Create Procedure with query
CREATE PROCEDURE setData
(imgURL IN varchar(200)) AS
BEGIN
insert into table_name values() //write query here
END;
I Dont know what mysql version you are using, so query may be different for different database version.
Then Simply call the method by using callable statement
class DemoStoredProcedure
{
public static void main(String args[])
{
Connection conn = null;
CallableStatement stmt = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("Your connection URL HREeee","usrname","password");
String sql = "{call setData (?)}";
stmt = conn.prepareCall(sql);
String url="images/a.jpg";
stmt.setString(1,url);
stmt.execute();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
}
I hope I have done what you want, This way you can save the imgUrl to the database.

Nikesh Joshi
- 824
- 6
- 17