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

📄 resultset.java.svn-base

📁 利用J2ME编写的手机应用程序。 功能包括显示图片
💻 SVN-BASE
字号:
package wFramework;

import java.io.IOException;
import java.util.Vector;
import org.kxml2.io.KXmlParser;

import com.sun.perseus.model.Time;

public class ResultSet 
{
	private KXmlParser parser;
	private Vector columns, dataset;
	private Statement statement;
	private int scode;
	private String errormsg;

	ResultSet(KXmlParser parser, Statement statement)
	{
		this.parser = parser;
		this.statement = statement;
		columns = new Vector();
		dataset = new Vector();
		
		scode = 0;
		errormsg = "";
		
		try
		{
			int type = parser.nextToken();
			while (type != KXmlParser.END_DOCUMENT)
			{
				String cmd = parser.getName();
				if (type == KXmlParser.START_TAG)
				{
					if (cmd.equalsIgnoreCase("response"))
					{
						scode = Integer.parseInt(parser.getAttributeValue(null, "scode"));
						if (scode != 200)
							errormsg = parser.getAttributeValue(null, "msg");
					}
					else if (cmd.equalsIgnoreCase("coldef"))
					{
						String cName = parser.getAttributeValue(null, "name");
						String cType = parser.getAttributeValue(null, "type");
						columns.addElement(new ResultSetColumn(cName, cType));
					}
				}
				else if (type == KXmlParser.END_TAG)
				{
					if (cmd.equalsIgnoreCase("metadata"))
						break;
				}
				type = parser.nextToken();
			}
		}
		catch (Exception e)
		{
			if (errormsg.length() == 0)
				errormsg = "An exception occured while parsing XML: " + e.toString();
		}
		
		gotoTag("resultset", KXmlParser.START_TAG);
	}
	
	private boolean gotoTag(String name, int itype)
	{
		if (scode != 200) return false;
		
		try
		{
			int type = parser.nextToken();
			while (type != KXmlParser.END_DOCUMENT)
			{
				String cmd = parser.getName();
				if (type == itype && cmd.equalsIgnoreCase(name))
					return true;
				type = parser.nextToken();
			}
		}
		catch (Exception e)
		{
			if (errormsg.length() == 0)
				errormsg = "An exception occured while parsing XML: " + e.toString();
		}		
		return true;
	}
	
	public String getErrorMessage()
	{
		return errormsg;
	}
	
	public int getStatuscode()
	{
		return scode;
	}
	
	public void close()
	{
		parser.closeInput();
		parser = null;
		columns = null;
		dataset = null;
	}
	
	public String getColumnName(int columnIndex)
	{
		return columns.elementAt(columnIndex).toString();
	}
	
	public int getColumnCount()
	{
		return columns.size();
	}
	
	private int getColumnIndex(String columnName)
	{
		for (int i = 0; i < columns.size(); i++)
		{
			if (columnName.equalsIgnoreCase(columns.elementAt(i).toString()))
				return i;
		}
		return -1;
	}
	
	private String getColumnValue(String columnName)
	{
		return getColumnValue(getColumnIndex(columnName));
	}

	private String getColumnValue(int columnIndex)
	{
		return ((ResultSetColumn)dataset.elementAt(columnIndex)).getDatatype();
	}

	public boolean next()
	{
		if (scode != 200) return false;

		String cName = "";
		String cValue = "";
		dataset.removeAllElements();
		try
		{
			int type = parser.nextToken();
			while (type != KXmlParser.END_DOCUMENT)
			{
				String cmd = parser.getName();
				if (type == KXmlParser.START_TAG)
				{
					if (cmd.equalsIgnoreCase("col"))
						cName = parser.getAttributeValue(null, "name");
				}
				else if (type == KXmlParser.TEXT && cName.length() > 0)
				{
					cValue = parser.getText();					
					dataset.addElement(new ResultSetColumn(cName, cValue));
					cName = "";
				}
				else if (type == KXmlParser.END_TAG)
				{
					if (cmd.equalsIgnoreCase("row"))
						break;
					else if (cmd.equalsIgnoreCase("resultset"))
						return false;
				}
				type = parser.nextToken();
			}
		}
		catch (Exception e)
		{
			if (errormsg.length() == 0)
				errormsg = "An exception occured while parsing XML: " + e.toString();
			return false;
		}		
		return true;
	}
	
	public boolean getBoolean(String columnName)
	{
		return getBoolean(getColumnIndex(columnName));
	}
	
	public boolean getBoolean(int columnIndex)
	{
		int val = Integer.parseInt(getColumnValue(columnIndex));
		if (val != 0)
			return true;
		else
			return false;
	}

	public long getLong(String columnName)
	{	
		return getLong(getColumnIndex(columnName));
	}

	public long getLong(int columnIndex)
	{
		return Long.parseLong(getColumnValue(columnIndex));
	}
	
	public float getFloat(String columnName)
	{
		return Float.parseFloat(getColumnValue(columnName));
	}
	
	public float getFloat(int columnIndex)
	{
		return Float.parseFloat(getColumnValue(columnIndex));
	}
	
	public double getDouble(String columnName)
	{
		return Double.parseDouble(getColumnValue(columnName));
	}
	
	public double getDouble(int columnIndex)
	{
		return Double.parseDouble(getColumnValue(columnIndex));
	}

	public int getInt(String columnName)
	{
		return Integer.parseInt(getColumnValue(columnName));
	}
	
	public int getInt(int columnIndex)
	{
		return Integer.parseInt(getColumnValue(columnIndex));
	}
	
	public short getShort(String columnName)
	{
		return Short.parseShort(getColumnValue(columnName));
	}

	public short getShort(int columnIndex)
	{
		return Short.parseShort(getColumnValue(columnIndex));
	}
	
	public String getString(String columnName)
	{
		return getColumnValue(columnName);
	}

	public String getString(int columnIndex)
	{
		return getColumnValue(columnIndex);
	}
	
	public Polygon getPolygon(String columnName)
	{
		return new Polygon(getColumnValue(columnName));
	}
	
	public Polygon getPolygon(int columnIndex)
	{
		return new Polygon(getColumnValue(columnIndex));
	}
	
	public Polyline getPolyline(String columnName)
	{
		return new Polyline(getColumnValue(columnName));		
	}

	public Polyline getPolyline(int columnIndex)
	{
		return new Polyline(getColumnValue(columnIndex));		
	}

	public Point getPoint(String columnName)
	{
		return new Point(getColumnValue(columnName));		
	}

	public Point getPoint(int columnIndex)
	{
		return new Point(getColumnValue(columnIndex));		
	}

	public String getDatatype(String columnName)
	{
		return getDatatype(getColumnIndex(columnName));
	}
	
	public String getDatatype(int columnIndex)
	{
		return ((ResultSetColumn)columns.elementAt(columnIndex)).getDatatype();
	}	
	
	public Statement getStatement()
	{
		return statement;
	}
}

⌨️ 快捷键说明

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