In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
To treasure some pieces of content that are often used in the development process, the following information is about the simple implementation of java large object access.
Package info.itlanguageexpress.LargeObject
Import java.io.File
Import java.io.FileInputStream
Import java.io.FileOutputStream
Import java.io.IOException
Import java.io.InputStream
Import java.sql.Connection
Import java.sql.DriverManager
Import java.sql.PreparedStatement
Import java.sql.ResultSet
Import java.sql.SQLException
Public class MySqlLargeObjectAccess {
Public static String DRIVER = "org.gjt.mm.mysql.Driver"; public static String USER = "root"; public static String PASSWORD = "your password"; public static void main (String [] args) throws Exception {Connection conn = null; try {Class.forName (DRIVER); conn = DriverManager.getConnection (URL, USER, PASSWORD); insertWordFileToMySql (conn); fetchWordFileFromMySql (conn);} catch (Exception ex) {ex.printStackTrace (System.out) } finally {try {conn.close ();} catch (Exception ex) {}} public static void insertWordFileToMySql (Connection conn) throws SQLException, IOException {PreparedStatement pstm = conn .prepareStatement ("insert into wordInputTest values (?)"; pstm.setString (1, "docx1"); InputStream in = new FileInputStream ("F:" + File.separator + "test1.docx") Pstm.setBinaryStream (2, in, in.available ()); pstm.executeUpdate (); pstm.close ();} public static void fetchWordFileFromMySql (Connection conn) throws SQLException, IOException {PreparedStatement pstm = conn pstm.setString (1, "docx1"); ResultSet rs = pstm.executeQuery (); int count = 1; while (rs.next ()) {InputStream in = rs.getBinaryStream ("file") FileOutputStream out = new FileOutputStream ("F:" + File.separator + "testcopy" + count + ".docx"); byte [] b = new byte [1024]; int len = 0; while ((len = in.read (b))! =-1) {out.write (b, 0, len); out.flush ();} out.close () In.close (); count++;} rs.close (); pstm.close ();}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.