⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmtop.java

📁 一个JAVA做的博客系统。系统采用JSP + JS + TOMCAT + MYSQL制作。用户能上传图片和音乐到系统中。游客和用户自己能在页面中浏览文件和听歌。
💻 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 + -