football.java

来自「手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环」· Java 代码 · 共 101 行

JAVA
101
字号
/**
 * @(#)FootBall.java	
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	余煜辉
 */

package com.j2me.data;

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

/*
 *此类是用来足球的数据库连接,查询的数据库连接类
 */
public class FootBall extends DataConnect
{
	public FootBall()
	{
	}

	/*获得执行SQL语句后的结果集方法*/
	public ResultSet view(String sql)
		throws SQLException, Exception
	{
		ResultSet rs = null;
  
		
		try
		{					
			Statement stmt = con.createStatement();
		    rs = stmt.executeQuery(sql);
		}
		catch(SQLException sqlexception)
		{
			error = "SQLException: Could not execute the query.";
			throw new SQLException(error);
		}
		catch(Exception e)
		{
			error = "Exception: An unknow error occurred while retrieving User.";
			throw new Exception(error);
		}
		return rs;
	}

	/*插入数据的方法, sql为执行语句, data要插入数据的数据, str为只有一个数据时的参数,length为要插入数据的字段数*/
	public void insertData(String sql, String[] data, int str, int length)
		throws SQLException, Exception
	{
		if (con != null)
		{
			PreparedStatement updataFootBall;
			try
			{
				updataFootBall = con.prepareStatement(sql);

				/*判断,当只有一个参数时执行的操作*/
				if (length == 0 && data == null)
				{
					updataFootBall.setInt(1, str); 
					updataFootBall.execute();
				}
				else
				{
					for (int i = 1; i <= length; i++)
					{	  
						updataFootBall.setString(i, data[i-1]);	
					}
					updataFootBall.execute();
				}								
			}
			catch(SQLException sqlexception)
			{
				error = "SQLException: updata faile, possible duplicate entry.";
				throw new SQLException(error);
			}
		}
		else
		{
			error = "Exception: Connection to database was lost.";
			throw new Exception(error);
		}
	} 

}



		









⌨️ 快捷键说明

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