database.java


  データベースアクセスの為の Beans




作成場所
  

C:\Webhost\tomcat5.5\WEB-INF\classes\lightbox
  

database.class 作成サンプル (バッチファイル)
  

javac
 -classpath
 "..\;C:\Tomcat5.5\common\lib\servlet-api.jar;C:\Tomcat5.5\common\lib\jsp-api.jar"
 database.java
 -Xlint:unchecked 
  

  

package lightbox;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;

public class database {

	private webapp gbl;
	private Connection con;
	public Statement stmt;
	public ResultSet rset;

	// *****************************************************
	// 初期化
	// *****************************************************
	public void Initialize( webapp my ) {

		gbl = my;

	}

	// *****************************************************
	// 接続文字列の補助
	// *****************************************************
	public void ConnectHelp( ) {

		String strWork;
		String Mess1 = "web.xml よりセットしました";
		String Mess2 = "ユーザがセットしています";
		String Mess3 = "セットできませんでした";

		strWork = gbl.get( "DriverName" );
		if ( strWork.equals( "" ) ) {
			strWork = gbl.getApplication("DriverName");
			if ( strWork == null ) {
				gbl.set(
					"DriverName", "sun.jdbc.odbc.JdbcOdbcDriver"
				);
				gbl.set(
					"SET_DriverName", "デフォルトをセットしました"
				);
			}
			else {
				gbl.set( "DriverName", strWork );
				gbl.set( "SET_DriverName", Mess1 );
			}
		}
		else {
			gbl.set( "SET_DriverName", Mess2 );
		}

		strWork = gbl.get( "ConnectionUrl" );
		if ( strWork.equals( "" ) ) {
			strWork = gbl.getApplication("ConnectionUrl");
			if ( strWork == null ) {
				gbl.set( "ConnectionUrl", Mess3 );
			}
			else {
				gbl.set( "ConnectionUrl", strWork );
				gbl.set( "SET_ConnectionUrl", Mess1 );
			}
		}
		else {
			gbl.set( "SET_ConnectionUrl", Mess2 );
		}

		strWork = gbl.get( "ConnectionDbname" );
		if ( strWork.equals( "" ) ) {
			strWork = gbl.getApplication("ConnectionDbname");
			if ( strWork == null ) {
				gbl.set( "ConnectionDbname", Mess3 );
			}
			else {
				gbl.set( "ConnectionDbname", strWork );
				gbl.set( "SET_ConnectionDbname", Mess1 );
			}
		}
		else {
			gbl.set( "SET_ConnectionDbname", Mess2 );
		}

		strWork = gbl.get( "ConnectionUser" );
		if ( strWork.equals( "" ) ) {
			strWork = gbl.getApplication("ConnectionUser");
			if ( strWork == null ) {
				gbl.set( "ConnectionUser", Mess3 );
			}
			else {
				gbl.set( "ConnectionUser", strWork );
				gbl.set( "SET_ConnectionUser", Mess1 );
			}
		}
		else {
			gbl.set( "SET_ConnectionUser", Mess2 );
		}

		strWork = gbl.get( "ConnectionPass" );
		if ( strWork.equals( "" ) ) {
			strWork = gbl.getApplication("ConnectionPass");
			if ( strWork == null ) {
				gbl.set( "ConnectionPass", Mess3 );
			}
			else {
				gbl.set( "ConnectionPass", strWork );
				gbl.set( "SET_ConnectionPass", Mess1 );
			}
		}
		else {
			gbl.set( "SET_ConnectionPass", Mess2 );
		}

	}

	// *****************************************************
	// ドライバ文字列セット
	// *****************************************************
	public void setDriverName( String strName ) {

		gbl.put( "DriverName", strName );

	}

	// *****************************************************
	// DB 接続 URL セット
	// *****************************************************
	public void setConnectionUrl( String strUrl ) {

		gbl.put( "ConnectionUrl", strUrl );

	}

	// *****************************************************
	// DB 接続 Dbname セット
	// *****************************************************
	public void setConnectionDbname( String strUrl ) {

		gbl.put( "ConnectionDbname", strUrl );

	}

	// *****************************************************
	// DB 接続 User セット
	// *****************************************************
	public void setConnectionUser( String strUser) {

		gbl.put( "ConnectionUser", strUser );

	}

	// *****************************************************
	// DB 接続 Password セット
	// *****************************************************
	public void setConnectionPass( String strPass ) {

		gbl.put( "ConnectionPass", strPass );

	}

	// *****************************************************
	// DB 接続
	// *****************************************************
	public boolean Connect( ) throws Exception {

		ConnectHelp( );

		gbl.put( "ERROR_CONNECT", "OK" );

		Class.forName( gbl.get( "DriverName" ) );

		try {
			con = DriverManager.getConnection(
				gbl.get( "ConnectionUrl" ),
				gbl.get( "ConnectionUser" ),
				gbl.get( "ConnectionPass" )
			);
			stmt = con.createStatement();
			if ( !gbl.get( "ConnectionDbname" ).equals( "" ) ) {
				stmt.executeUpdate(
					"use " + gbl.get( "ConnectionDbname" )
				);
			}

			return true;
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_CONNECT", e.getMessage() );
			return false;
		}

	}

	// *****************************************************
	// DB 接続解除
	// *****************************************************
	public void DisConnect( ) throws Exception {

		gbl.put( "ERROR_DISCONNECT", "OK" );

		try {
			stmt.close();
			con.close();
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_DISCONNECT", e.getMessage() );
		}

	}

	// *****************************************************
	// レコードセット取得
	// *****************************************************
	public boolean Query( String Sql ) throws Exception {

		gbl.put( "ERROR_QUERY", "OK" );

		boolean bRet = true;

		try {
			rset = stmt.executeQuery ( Sql );
			bRet = rset.next();
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_QUERY", e.getMessage() );
			bRet = false;
		}

		return bRet;
	}
	public boolean Query() throws Exception {

		gbl.put( "ERROR_QUERY_NEXT", "OK" );
		boolean bRet = true;

		try {
			bRet = rset.next();
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_QUERY_NEXT", e.getMessage() );
			bRet = false;
		}

		return bRet;
	}

	// *****************************************************
	// 列データ取得
	// *****************************************************
	public String Fields( String strName ) throws Exception {

		gbl.put( "ERROR_FIELDS", "OK" );
		String strResult = "";

		try {
			strResult = rset.getString( strName );
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_FIELDS", e.getMessage() );
		}

		return strResult;
	}

	// *****************************************************
	// DB 更新処理
	// *****************************************************
	public int Execute( String Query ) throws Exception {

		gbl.put( "ERROR_SQL", "OK" );
		int nRet;

		try {
			nRet = stmt.executeUpdate( Query );
		}
		catch( SQLException e ) {
			gbl.put( "ERROR_SQL", e.getMessage() );
			return -1;
		}

		return nRet;

	}

}
  










yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[jsp]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/11/14 02:44:59
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube