亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? dbutil.java

?? Sun公司Dream項目
?? JAVA
字號:
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 *
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.php
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * http://www.opensource.org/licenses/cddl1.php.  If 
 * applicable, add the following below this CDDL HEADER, 
 * with the fields enclosed by brackets "[]" replaced 
 * with your own identifying information: 
 * Portions Copyright [yyyy]
 * [name of copyright owner]
 */ 

/*
 * $(@)DBUtil.java $Revision: 1.1.1.1 $ $Date: 2006/07/24 21:56:11 $
 * 
 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
 */




/*

 * @(#)DBUtil.java  1.1 05/11/09

 *

 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.

 */





package com.sun.dream.shop;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.util.Vector;



import java.sql.*;

import java.util.*;

import javax.sql.*;

import javax.ejb.*;

import javax.naming.*;





/**

 *

 * To change the template for this generated type comment go to

 * Window - Preferences - Java - Code Generation - Code and Comments

 */

public class DBUtil {

	

	//public static final String DEFAULT_DATA_SOURCE = "java:comp/env/jdbc/operaserverdb";

	public static DataSource dataSource;

		

	public static Connection getConnection()

		throws ShopException {

		try {

                        InitialContext ic = new InitialContext();

                        dataSource = (DataSource) ic.lookup("jdbc/sample");

        

			//Class.forName(ShopServlet.iProperties.getProperty(Const.DATABASE_DRIVER, "org.hsqldb.jdbcDriver"));

			//return  DriverManager.getConnection(

			//		ShopServlet.iProperties.getProperty(Const.DATABASE_URL,"jdbc:hsqldb:hsql://localhost"), 

			//		ShopServlet.iProperties.getProperty(Const.DATABASE_USERNAME, "demo"), 

			//		ShopServlet.iProperties.getProperty(Const.DATABASE_PASSWORD, "demo"));			

                        return dataSource.getConnection();

			

		} catch (Exception ex) {

                        System.out.println (ex.toString());

			throw new ShopException(ShopException.DATABASE_CONNECTION_ERROR , 

				ex.toString());

			

		}

	}

	

	public static String[] getRecord(String sql, int[] sqlTypes, 

		String[] formats, Object[] params) 

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;

		ResultSet results = null;

		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);

		

			if (params != null) {

				for (int i = 0; i < params.length; i++) {

					st.setObject(i + 1, params[i]);

				}

			}



			results = st.executeQuery();



			if (!results.next()) {

				return null;

			}

			String[] resultStrings = new String[sqlTypes.length];

			int numFields = resultStrings.length;

			if (formats == null) {

				for (int i = 0; i < numFields; i++) {

					resultStrings[i] =

						getFormattedValue(results, i + 1, sqlTypes[i], null);

				}

			} else {

				for (int i = 0; i < numFields; i++) {

					resultStrings[i] =

						getFormattedValue(

							results,

							i + 1,

							sqlTypes[i],

							formats[i]);

				}

			}

			return resultStrings;

		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(results);

			close(st);

			close(conn);

		}

	}



	public static Vector getRecords(

		String sql,

		int[] sqlTypes,

		String[] formats)

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;

		ResultSet results = null;

		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);

			results = st.executeQuery();



			Vector records = new Vector();

			while (results.next()) {

				String[] resultStrings = new String[sqlTypes.length];

				int numFields = resultStrings.length;

				if (formats == null) {

					for (int i = 0; i < numFields; i++) {

						resultStrings[i] =

							getFormattedValue(

								results,

								i + 1,

								sqlTypes[i],

								null);

					}

				} else {

					for (int i = 0; i < numFields; i++) {

						resultStrings[i] =

							getFormattedValue(

								results,

								i + 1,

								sqlTypes[i],

								formats[i]);

					}

				}

				records.addElement(resultStrings);

			}

			return records;

		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(results);

			close(st);

			close(conn);

		}

	}

	

	public static String getField(

		String sql,

		int sqlType,

		String format)

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;

		ResultSet results = null;

		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);

			results = st.executeQuery();



			if (!results.next()) {

				return null;

			}



			return getFormattedValue(results, 1, sqlType, format);



		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(results);

			close(st);

			close(conn);

		}

	}



	public static Vector getFields(

		String sql,

		int sqlType,

		String format)

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;

		ResultSet results = null;



		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);

			results = st.executeQuery();

			Vector fieldVec = new Vector();

			while (results.next()) {

				fieldVec.addElement(

					getFormattedValue(results, 1, sqlType, format));

			}



			return fieldVec;



		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(results);

			close(st);

			close(conn);

		}

	}



	public static boolean execute(String sql)

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;



		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);

			boolean result = st.execute();

			return result;

		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(st);

			close(conn);

		}

	}



	public static boolean execute(

		String sql,

		Object[] params)

		throws ShopException {



		Connection conn = null;

		PreparedStatement st = null;



		try {

			conn = getConnection();

			st = conn.prepareStatement(sql);



			if (params != null) {



				int numParams = params.length;

				for (int i = 0; i < numParams; i++) {

					st.setObject(i + 1, params[i]);

				}

			}

			boolean result = st.execute();

			return result;

		} catch (java.sql.SQLException ex) {

			ex.printStackTrace();

			throw new ShopException (ShopException.DATABASE_CONNECTION_ERROR,

					ex.toString());

		} finally {

			close(st);

			close(conn);

		}

	}

		

	public static String getFormattedValue(

		ResultSet rs,

		int colIndex,

		int colType,

		String format)

		throws SQLException {



		switch (colType) {

			case java.sql.Types.INTEGER :

				if (format == null)

					return Integer.toString(rs.getInt(colIndex));

				else

					return new DecimalFormat(format).format(

						rs.getInt(colIndex));

			case java.sql.Types.FLOAT :

				if (format == null)

					return Float.toString(rs.getFloat(colIndex));

				else

					return new DecimalFormat(format).format(

						rs.getFloat(colIndex));

			case java.sql.Types.TIMESTAMP :

				if (format == null)

					return rs.getTimestamp(colIndex).toString();

				else

					return new SimpleDateFormat(format).format(

						rs.getTimestamp(colIndex));

			case java.sql.Types.DATE :

				java.sql.Date date = rs.getDate(colIndex);

				if (date == null)

					return "N/A";

				if (format == null)

					return date.toString();

				else

					return new SimpleDateFormat(format).format(date);

			case java.sql.Types.BIT :

				//if (format == null)

				return new Boolean(rs.getBoolean(colIndex)).toString();

			default :

				return rs.getString(colIndex);

		}

	}	



	public static void close(Connection con) {

		if (con != null) {

		  try {

			con.close();

		  } catch (SQLException e) {

		  }

		}		

	}

	public static void close(ResultSet rs) {

		if (rs != null) {

		  try {

			rs.close();

		  } catch (SQLException e) {

		  }

		}		

	}

	public static void close(java.sql.Statement st) {

		if (st != null) {

		  try {

			st.close();

		  } catch (SQLException e) {

		  }

		}		

	}



}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲va天堂va国产va久| 亚洲综合偷拍欧美一区色| 国产精品久久免费看| 亚洲综合在线第一页| 久草在线在线精品观看| 91蝌蚪国产九色| 精品久久久网站| 亚洲一区二三区| 99久久婷婷国产综合精品| 欧美va亚洲va香蕉在线| 亚洲一区欧美一区| 91在线丨porny丨国产| 日韩欧美国产系列| 天天综合网 天天综合色| 成人动漫一区二区三区| 精品伦理精品一区| 日本视频一区二区| 在线亚洲欧美专区二区| 国产精品嫩草99a| 国产在线视频精品一区| 日韩视频免费观看高清完整版在线观看| 中文字幕永久在线不卡| 国产一区二区在线免费观看| 欧美一区二区三区视频免费| 亚洲韩国精品一区| 99精品在线观看视频| 国产欧美日本一区二区三区| 久久精品72免费观看| 欧美一区二区三区免费| 亚洲一区电影777| 欧美亚洲尤物久久| 亚洲美女屁股眼交3| 成人精品一区二区三区中文字幕| 久久精品一区四区| 国产精品一区2区| 久久精品欧美一区二区三区不卡 | 欧美一级在线免费| 天天色天天爱天天射综合| 色狠狠一区二区三区香蕉| 日韩一区在线看| 91美女在线看| 亚洲国产一区视频| 欧美情侣在线播放| 免费av成人在线| 日韩欧美的一区二区| 激情图片小说一区| 久久精品一区二区三区av| 亚洲综合自拍偷拍| 色欧美片视频在线观看| 一区二区三区在线视频观看58| 97精品电影院| 亚洲狠狠丁香婷婷综合久久久| 99久久99久久综合| 国产偷国产偷亚洲高清人白洁| 日韩福利电影在线| 欧美一级理论性理论a| 日韩国产欧美视频| 欧美r级在线观看| 国产福利视频一区二区三区| 国产女同互慰高潮91漫画| 99国产欧美久久久精品| 亚洲视频1区2区| 欧美午夜片在线观看| 亚洲国产色一区| 欧美日韩1234| 麻豆精品一区二区av白丝在线| 欧美日韩国产中文| 免费久久99精品国产| 久久婷婷久久一区二区三区| 国产ts人妖一区二区| 国产精品国产三级国产aⅴ入口| 91美女视频网站| 五月综合激情网| 日韩午夜av一区| av在线一区二区| 日韩中文字幕麻豆| 久久综合狠狠综合久久综合88| 狠狠色丁香婷综合久久| 国产精品电影院| 欧美日韩国产一区| 日韩激情视频网站| 亚洲三级在线播放| 91精品在线免费| 国产成人免费视频精品含羞草妖精| 国产精品电影院| 3d成人动漫网站| 成人国产电影网| 亚洲一本大道在线| 精品国免费一区二区三区| 成人av在线影院| 日韩精品久久久久久| 精品国产91乱码一区二区三区| 欧美午夜一区二区| 国产成人综合视频| 亚洲bdsm女犯bdsm网站| 久久免费看少妇高潮| 在线观看国产日韩| 丁香婷婷综合激情五月色| 三级欧美在线一区| 亚洲视频你懂的| 久久夜色精品国产噜噜av| 精品一区二区三区免费| 国产精品美女久久久久高潮| 欧美一级黄色大片| 色美美综合视频| 国产91在线观看| 麻豆成人av在线| 一区二区三区日本| 国产精品久久久久久久久动漫| 欧美videofree性高清杂交| 欧美日韩国产综合草草| 国产很黄免费观看久久| 国产做a爰片久久毛片| 天天综合色天天综合| 一区二区三区欧美久久| 国产精品沙发午睡系列990531| 精品美女被调教视频大全网站| 99久久精品久久久久久清纯| 国产伦理精品不卡| 精品无人码麻豆乱码1区2区| 亚洲成人1区2区| 中文字幕日本不卡| 国产精品五月天| 久久精品一区四区| 久久久久久毛片| 欧美大尺度电影在线| 欧美日韩国产一二三| 欧美天堂一区二区三区| 色综合网色综合| 91免费观看在线| 色综合久久久久久久久久久| 国产成人啪免费观看软件| 午夜精品久久久久久| 一区二区三区在线视频播放| 亚洲精品菠萝久久久久久久| 亚洲人成伊人成综合网小说| 中文字幕一区三区| 亚洲免费在线视频一区 二区| 亚洲欧洲另类国产综合| 国产精品网友自拍| 国产精品久久久久aaaa| 久久先锋资源网| 亚洲男人的天堂一区二区| 一区二区三区.www| 亚洲成人黄色小说| 日本不卡视频一二三区| 日韩av电影免费观看高清完整版| 天堂在线亚洲视频| 免播放器亚洲一区| 国产成人日日夜夜| 在线成人av影院| 欧美电视剧免费观看| 日本一区二区三区视频视频| 中文字幕一区二区在线播放| 亚洲精品乱码久久久久久久久| 亚洲一二三区不卡| 久久er99精品| 国产麻豆精品在线观看| 精品视频一区三区九区| 日韩一区二区在线免费观看| 国产亚洲福利社区一区| 亚洲图片你懂的| 亚洲欧美日韩国产综合| 视频一区中文字幕国产| 国产精品中文字幕欧美| 色哟哟一区二区三区| 91超碰这里只有精品国产| 国产亚洲一区字幕| 亚洲国产中文字幕在线视频综合| 老色鬼精品视频在线观看播放| 国产精品1区二区.| 欧美日韩精品一区二区| 日韩精品一区二区三区视频| 中文字幕在线不卡视频| 日韩综合小视频| 99综合电影在线视频| 本田岬高潮一区二区三区| 欧美大片在线观看一区| 亚洲女爱视频在线| 国产精一品亚洲二区在线视频| 91在线视频播放地址| 欧美大胆人体bbbb| 夜夜爽夜夜爽精品视频| 极品尤物av久久免费看| 国产99久久精品| 91最新地址在线播放| 在线精品视频免费播放| 欧美日韩极品在线观看一区| www激情久久| 亚洲天堂成人网| 韩国三级在线一区| 91社区在线播放| 欧美午夜精品久久久久久超碰| 国产亚洲成年网址在线观看| 午夜精彩视频在线观看不卡| 不卡免费追剧大全电视剧网站| 欧美这里有精品| 亚洲一区日韩精品中文字幕| 成人av中文字幕| 亚洲国产精品传媒在线观看|