public class ImageOnHana {
public static final String hanaURL = "jdbc:sap://<hostname>:3<instance>15/";
public static final String hanaUser = "AVIR11";
public static final String hanaPassword = "ABCD1234";
public static final String pics = "C:\\Pictures";
public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException {
Class.forName("com.sap.db.jdbc.Driver");
Connection conn = DriverManager.getConnection(hanaURL,hanaUser,hanaPassword); //Open HDB Connection
conn.setAutoCommit(false);
String query = "INSERT INTO \"AVIR11\".\"EMP_IMAGES\" VALUES(?,?)";
PreparedStatement pstmt = conn.prepareStatement(query);
File folder = new File(pics);
File[] images = folder.listFiles();
System.out.println("*****OPEN FILES NOW****");
try {
if (images != null) {
for (File image : images) {
String imgName = image.getName();
FileInputStream fis = new FileInputStream(image);
pstmt = conn.prepareStatement(query);
String[] parts = imgName.toUpperCase().split(".JPG");
String id = parts[0];
pstmt.setInt(1, Integer.parseInt(id));
pstmt.setBinaryStream(2, fis, (int) image.length());
pstmt.executeUpdate();
conn.commit();
System.out.println(imgName + " image upload to HANA successful");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
var empId = $.request.parameters.get("empId");
var conn = $.db.getConnection();
try {
var query = "SELECT IMAGE FROM \"AVIR11\".\"EMP_IMAGES\" WHERE ID = ?";
var pstmt = conn.prepareStatement(query);
pstmt.setInteger(1,parseInt(empId));
var rs = pstmt.executeQuery();
if(rs.next()){
$.response.headers.set("Content-Disposition", "Content-Disposition: attachment; filename=image.jpg");
$.response.contentType = 'image/jpg';
$.response.setBody(rs.getBlob(1));
}
} catch (e) {
}
conn.close();
<Image src="http://<hostname>:8000/avinash/services/XJ_Emp_Images.xsjs?empId=1"
width="100%" height="150px">
<layoutData><l:GridData span=”” linebreakL=””/></layoutData>
</Image>
byId("image").setSrc("http://<hostname>:8000/avinash/services/XJ_Emp_Images.xsjs?empId="+employeeId+"");
SAP HANA Consultant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |