commentmanager.java

来自「bbs论坛系统」· Java 代码 · 共 63 行

JAVA
63
字号
package struts.business;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class CommentManager {
	
    private static final String validate_question="Select * from comment where title=?and type=?";
	private static final String insert_question="insert into comment(name,title,text,type,floor) values(?,?,?,?,?)";
	public boolean validate(String title,String type)throws Exception
	{
		Connection con=null;
		DBUtility db=DBUtility.getInstance();
		try{
			con=db.getConnection();
			PreparedStatement stmt=con.prepareStatement(validate_question);
			stmt.setString(1,title);
			stmt.setString(2,type);
			ResultSet rs=stmt.executeQuery();
			if(rs.next())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw e;
		}
	}
	public int insert(String name,String title,String text,
			String type,int floor ) throws Exception 
	{
		Connection con=null;
		String strSql;
		int result=0;
		DBUtility db=DBUtility.getInstance();
		try
		{
			con=db.getConnection();
			PreparedStatement stmt=con.prepareStatement(insert_question);
			stmt.setString(1, name);
			stmt.setString(2, title);
			stmt.setString(3, text);
			stmt.setString(4, type);
			stmt.setInt(5,floor);
			result=stmt.executeUpdate();
			con.close();
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
		return result;
	}
   
}

⌨️ 快捷键说明

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