Home >Java >javaTutorial >Detailed explanation of how Java implements sql statements that generate images and store them in the database
This article mainly introduces relevant information that explains in detail how to implement the sql statement that JAVA generates and stores images into the database. Here is an example of how to generate images in java and store them in the database. Friends in need can refer to it
Detailed explanation of the implementation method of JAVA generating sql statements for storing pictures in the database
Implementation code:
The comments are very clear and will not be repeated~
public class Image2Hex { public static void main(String[] args) { try{ //存放图片的文件夹 File list = new File("d:/qmx"); File[] lists = list.listFiles(); String name; //生成的语句存放文件 PrintWriter pw = new PrintWriter(new FileWriter("d:/update.txt"),true); FileInputStream fis = null; byte[] b; for(File file : lists){ //张三.jpg name=file.getName(); fis = new FileInputStream(file); b = new byte[fis.available()]; fis.read(b); pw.println("update sys_userinfo set sign_image =0x" + byte2HexStr(b) + " where realName=\'" + name.substring(0,name.length() - 4) + "\'"); } pw.flush(); pw.close(); }catch(Exception e){ e.printStackTrace(); } } /** * * 描述:byte转字符串 */ public static String byte2HexStr(byte[] b) { StringBuffer hs = new StringBuffer(); String stmp=""; for (int n=0;n< b.length;n++) { stmp=(Integer.toHexString(b[n] & 0XFF)); hs.append((stmp.length() == 1 ? "0" : "") + stmp); } return hs.toString().toUpperCase(); } }
The current project needs to store signature pictures of employees of the user company. Hundreds of pictures made by the artist need to be stored in the database, so I wrote this one to read the pictures into hexadecimal and The method of spelling the update statement and storing it in a text document works well.
The above is the detailed content of Detailed explanation of how Java implements sql statements that generate images and store them in the database. For more information, please follow other related articles on the PHP Chinese website!