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

📄 titleop.java

📁 一个JAVA做的博客系统。系统采用JSP + JS + TOMCAT + MYSQL制作。用户能上传图片和音乐到系统中。游客和用户自己能在页面中浏览文件和听歌。
💻 JAVA
字号:
package essay;

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 common.DS;

public class TitleOp
{
	public static boolean insert(Title t)
	{
		int id = selId(t);
		if(id > 0)return false;
		String title = t.getTitle().replaceAll("'", "&sq&");
		JdbcTemplate jt = new JdbcTemplate(DS.getDs());
		jt.execute("insert into title(id, title, username, date) values("
			+ (selMaxId() + 1) + ", '" + title + "', '" + t.getUsername()
			+ "', '" + new Date().toLocaleString() + "')");
		return true;
	}
	public static int selMaxId()
	{
		String search = "select max(id) from title";
		ResultSet rs = null;
		PreparedStatement PS = null;
		int id = 0;
		try
		{
			PS = DS.getDs().getConnection().prepareStatement(search);
			rs = PS.executeQuery();
			if(rs.next())
				id = rs.getInt(1);
			rs.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			return id;
		}
	}
	public static int selId(Title t)
	{
		String search = "select id from title where username = ? and title = ?";
		ResultSet rs = null;
		PreparedStatement PS = null;
		int id = 0;
		try
		{
			PS = DS.getDs().getConnection().prepareStatement(search);
			PS.setString(1, t.getUsername());
			PS.setString(2, t.getTitle());
			rs = PS.executeQuery();
			if(rs.next())
				id = rs.getInt(1);
			rs.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			return id;
		}
	}
	public static String selTitle(int id)
	{
		String search = "select title from title where id = ?", title = null;
		ResultSet rs = null;
		PreparedStatement PS = null;
		try
		{
			PS = DS.getDs().getConnection().prepareStatement(search);
			PS.setInt(1, id);
			rs = PS.executeQuery();
			if(rs.next())
				title = rs.getString(1);
			rs.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			title = title.replaceAll(" ", " ").replaceAll("&sq&", "'");
			return title;
		}
	}
	public static Vector selAll() throws SQLException
    {
		String search = "select id, username, title, date from title order by id", t;
		ResultSet rs = null;
		PreparedStatement PS = null;
		Vector v = null;
		Title title = null;
		PS = DS.getDs().getConnection().prepareStatement(search);
		rs = PS.executeQuery();
		if(rs.isBeforeFirst())
			v = new Vector();
		while(rs.next())
		{
			t = rs.getString(3);
			t = t.replaceAll(" ", " ").replaceAll("&sq&", "'");
			title = new Title(rs.getInt(1), rs.getString(2), 
				t, rs.getTimestamp(4).toLocaleString());
			v.add(title);
		}
		rs.close();
		return v;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -