java 事物控制
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
String driver="";
String url="";
String user="";
String password="";
String serialNo="";
Connection conn1 = (Connection) getConnection2(driver,url,user,password);
String content = getContent(serialNo,conn1);
}
/**
* 获得数据库连接
* @throws SQLException
* */
private static java.sql.Connection getConnection2(String driver, String url, String user, String password) throws SQLException {
java.sql.Connection conn = null ;
try {
Class.forName(driver) ;
conn = DriverManager.getConnection(url, user, password) ;
return conn;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
/**
* 获得正文内容
* @return
* @throws IOException
* @throws SQLException
* */
private static String getContent(String serialNo,Connection conn) throws IOException, SQLException {
StringBuffer contentBuffer = new StringBuffer();
String content = "";
if(serialNo!=null){
java.sql.Connection connection = conn;
java.sql.PreparedStatement psStat = null;
Reader reader = null;
try {
psStat = connection.prepareStatement("select content from notice_info where serialno=?");
psStat.setString(1, serialNo);
java.sql.ResultSet rs = psStat.executeQuery();
if(rs.next()){
Clob clob = rs.getClob("content");
if(clob!=null){
reader=clob.getCharacterStream();
char buff[]=new char[1];
for(int i=0;(i=reader.read(buff))>0;)
{
contentBuffer.append(buff);
}
reader.close();
}
}
rs.close();
}finally{
if(psStat!=null) psStat.close();
if(connection!=null) connection.close();
}
if(contentBuffer.length()>0)
{
content = StringFunction.replace(contentBuffer.toString(), "${CONTENT_VIEW_PATH}", ARE.getProperty("DFS_HTTP_PATH")+"/content/imageview");
}
}
return content;
}