@Test public void testNewSQLParamInsert() throws Exception { SQLParams params = new SQLParams(); params.addSQLParam("id", "1", SQLParams.STRING); // ID,HOST_ID,PLUGIN_ID,CATEGORY_ID,NAME,DESCRIPTION,DATASOURCE_NAME,DRIVER,JDBC_URL,USERNAME,PASSWORD,VALIDATION_QUERY params.addSQLParam("blobname", "abcdblob", SQLParams.BLOB); params.addSQLParam("clobname", "abcdclob", SQLParams.CLOB); SQLExecutor.insertBean( "insert into test(id,blobname,clobname) values(#[id],#[blobname],#[clobname])", params); }
/** * CREATE TABLE CLOBFILE ( FILEID VARCHAR(100), FILENAME VARCHAR(100), FILESIZE BIGINT, * FILECONTENT CLOB(2147483647) ) */ public @Test void uploadClobFile() throws Exception { File file = new File("D:\\bbossgroups-3.5.1\\bboss-taglib\\readme.txt"); String sql = ""; try { sql = "INSERT INTO CLOBFILE (FILENAME,FILECONTENT,fileid,FILESIZE) VALUES(#[filename],#[FILECONTENT],#[FILEID],#[FILESIZE])"; SQLParams sqlparams = new SQLParams(); sqlparams.addSQLParam("filename", file.getName(), SQLParams.STRING); sqlparams.addSQLParamWithCharset("FILECONTENT", file, SQLParams.CLOBFILE, "GBK"); sqlparams.addSQLParam("FILEID", UUID.randomUUID().toString(), SQLParams.STRING); sqlparams.addSQLParam("FILESIZE", file.length(), SQLParams.LONG); SQLExecutor.insertBean(sql, sqlparams); } catch (Exception ex) { throw new Exception("上传附件关联临控指令布控信息附件失败:" + ex); } }
/** * 上传附件 * * @param inputStream * @param filename * @return * @throws Exception */ public boolean uploadFile(InputStream inputStream, long size, String filename) throws Exception { boolean result = true; String sql = ""; try { sql = "INSERT INTO filetable (FILENAME,FILECONTENT,fileid,FILESIZE) VALUES(#[filename],#[FILECONTENT],#[FILEID],#[FILESIZE])"; SQLParams sqlparams = new SQLParams(); sqlparams.addSQLParam("filename", filename, SQLParams.STRING); sqlparams.addSQLParam("FILECONTENT", inputStream, size, SQLParams.BLOBFILE); sqlparams.addSQLParam("FILEID", UUID.randomUUID().toString(), SQLParams.STRING); sqlparams.addSQLParam("FILESIZE", size, SQLParams.LONG); SQLExecutor.insertBean(sql, sqlparams); } catch (Exception ex) { ex.printStackTrace(); result = false; throw new Exception("上传附件关联临控指令布控信息附件失败:" + ex); } finally { if (inputStream != null) { inputStream.close(); } } return result; }