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

📄 twotitle.java

📁 jsp编程的源代码
💻 JAVA
字号:
package com.mybean;

import java.sql.*;
import java.util.ArrayList;
import com.myopdb.*;

public class TwoTitle {
	private int twoid;

	private int oneid;
	private String twotitle;

	private String onetitle;

	private String titlepath;

	private Connection con = null;

	private Statement stmt = null;

	private ResultSet rs = null;

	DBCon dbo = new DBCon();

	public String getTitlepath() {
		return titlepath;
	}

	public void setTitlepath(String titlepath) {
		this.titlepath = titlepath;
	}

	public String getTwotitle() {
		return twotitle;
	}

	public void setTwotitle(String twotitle) {
		this.twotitle = twotitle;
	}

	public boolean addTwoTitle(TwoTitle two) {
		return true;

	}

	public int getTwoid() {
		return twoid;
	}

	public void setTwoid(int twoid) {
		this.twoid = twoid;
	}

	public String getOnetitle() {
		return onetitle;
	}

	public void setOnetitle(String onetitle) {
		this.onetitle = onetitle;
	}

	public int getOneid() {
		return oneid;
	}

	public void setOneid(int oneid) {
		this.oneid = oneid;
	}

	public ArrayList getAllTwoTitle(String title) {
		String temp = title.substring(1, title.length() - 1);
		ArrayList<Object> lst = new ArrayList<Object>();
		this.con = dbo.getCon();
		TwoTitle two;
		final String sql = "select twotitle,titlepath from twoTitle where oneid in(select oneid from onetitle where onetitle='"
				+ temp + "')";
		try {
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				two = new TwoTitle();
				two.setTwotitle(rs.getString(1));
				two.setTitlepath(rs.getString(2));
				lst.add(two);
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return null;
		}
		return lst;
	}

	int intRowCount;// 数据的总记录数

	int intPageCount;// 总页数

	int intPageSize = 10;// 每页行数

	int intPage;// 当前第几页

	public ArrayList getAllTwoTitle(int curpage) {

		TwoTitle two;
		ArrayList<Object> lst = new ArrayList<Object>();
		final String sql = "select * from One_Two_view order by twoid";
		this.con = dbo.getCon();

		if (con != null) {
			try {
				stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
						ResultSet.CONCUR_UPDATABLE);
				rs = stmt.executeQuery(sql);
				rs.last();
				intRowCount = rs.getRow();
				System.out.println(intRowCount);
				if (intRowCount % intPageSize == 0) {
					intPageCount = intRowCount / intPageSize;
				} else {
					intPageCount = intRowCount / intPageSize + 1;
				}
				if (curpage == 0) {
					intPage = 1;
				} else {
					intPage = curpage;
					if (intPage < 1 || intPage > intPageCount) {
						intPage = 1;
					}
				}

				// 将对记录集进行操作,以显示数据,
				// 首先要将记录集的指针移到要显示页面的第一条记录上面
				rs.absolute((intPage - 1) * intPageSize + 1);
				// 循环显示当前指定页面的数据
				int i = 0;
				while (i < intPageSize && !rs.isAfterLast()) {
					two = new TwoTitle();
					two.setTwoid(rs.getInt(1));
					two.setOnetitle(rs.getString(2));
					two.setTwotitle(rs.getString(3));
					two.setTitlepath(rs.getString(4));
					lst.add(two);
					rs.next();
					i++;
				}

				System.out.println(i);
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
				return null;
			}
		}
		lst.add(this.intPage);
		lst.add(this.intPageCount);
		return lst;
	}


	public boolean inserTwoTitle(TwoTitle tt)
	{
		String sql="insert into twotitle values("+tt.getOneid()+",'"+tt.getTwotitle()+"','"+tt.getTitlepath()+"')";
		if(this.con==null)
		{
			this.con=dbo.getCon();
		}
		try {
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public boolean deleteTwoTitle(TwoTitle tt)
	{
		String sql="delete from twotitle where twoid="+tt.getTwoid()+"";
		if(this.con==null)
		{
			this.con=dbo.getCon();
		}
		try {
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return false;
		}
		return true;
	}
	public boolean updateTwoTitle(TwoTitle tt)
	{
		String sql="update twotitle set twotitle='"+tt.getTwotitle()+"',titlepath='"+tt.getTitlepath()+"' where twoid="+tt.getTwoid()+"";
		if(this.con==null)
		{
			this.con=dbo.getCon();
		}
		try {
			stmt=con.createStatement();
			stmt.executeUpdate(sql);
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
}

⌨️ 快捷键说明

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