showlistbean.java

来自「j2ee做的电子相册网站」· Java 代码 · 共 97 行

JAVA
97 行
字号
package userpicture;


import java.sql.*;
import java.io.*;
import java.util.*;


public class showlistBean {
	String fname[] = new String[1000];
	String id;
	String time[] = new String[1000];
	static long total = 0;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public void getPicture(String myid,String direction)
	{
		try {
				total = 0;
				Class.forName("com.mysql.jdbc.Driver");
				Connection c = DriverManager
						.getConnection("jdbc:mysql://localhost/myphone?user=root&password=123456"); // 连接mysql数据库
				Statement s = c.createStatement();
	
				String sql="select * from picture where ID='"+myid+"' and dirname='"+direction+"'"; 
				System.out.println(sql);
				ResultSet r = s.executeQuery(sql);
				int k = 0;
				while(r.next())
				{
					fname[k] = r.getString(2);
					time[k] = r.getString(5);
					k++;
					total++;
				}
				s.close();
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String getIndex(long index)
	{
		if(index < 0)
			index = 0;
		if(index > fname.length)
			index = fname.length - 1;
		System.out.println(fname[(int)index]);
		
		return fname[(int)index];
		
	}
	public long getnext(long num)
	{
		System.out.println("total: " +total);
		if(num < 0)
			return 0;
		if(num >= total-1)
			return total-1;
		return num+1;
	}
	
	public long getprivous(long num)
	{
		if(num <=0)
			return 0;
		return num-1;
	}
	
	public long getTotal()
	{
		return total;
	}
	
	public String gettime(long index)
	{
		if(index < 0)
			index = 0;
		if(index > fname.length)
			index = fname.length - 1;
		System.out.println(fname[(int)index]);
		
		return time[(int)index];
		
	}

}

⌨️ 快捷键说明

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