📄 cmtop.java
字号:
package cmt;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Vector;
import org.springframework.jdbc.core.JdbcTemplate;
import com.mysql.jdbc.Blob;
import common.DS;
public class CmtOp
{
public static void Insert(Comment c) throws Exception
{
JdbcTemplate jt = new JdbcTemplate(DS.getDs());
String comment = c.getComment().replaceAll("'", "&sq&");
jt.execute("insert into comment(titleid, username, comment, date) values("
+ c.getTitleId() + ", '" + c.getUsername() + "', '" + comment
+ "', '" + new Date().toLocaleString() + "')");
}
public static Vector selectAll(int titleId)
throws IOException, SQLException
{
String search = "select username, comment, date " +
"from comment where titleid = ? order by id";
ResultSet rs = null;
PreparedStatement PS = null;
Vector v = null;
Comment cmts = null;
Blob cmtBlob;
byte[] cmtBytes;
String cmtStr;
PS = DS.getDs().getConnection().prepareStatement(search);
PS.setInt(1, titleId);
rs = PS.executeQuery();
if(rs.isBeforeFirst())
v = new Vector();
while(rs.next())
{
cmtBlob = (Blob)rs.getBlob(2);
cmtBytes = cmtBlob.getBytes(1, (int)cmtBlob.length());
cmtStr = new String(cmtBytes);
cmtStr = cmtStr.replaceAll(" ", " ").replaceAll("&sq&", "'");
cmts = new Comment(rs.getString(1), cmtStr,
rs.getTimestamp(3).toLocaleString());
v.add(cmts);
}
rs.close();
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -