myswing パッケージ


  LboxDatabase.java



  
package myswing;

import java.sql.*;

public class LboxDatabase {

	private Connection con;
	public Statement stmt;
	public ResultSet rset;
	public String DriverName = "sun.jdbc.odbc.JdbcOdbcDriver";
	public String ConnectionUrl = "";
	public String ConnectionDbname = "";
	public String ConnectionUser = "";
	public String ConnectionPass = "";
	public String ErrorMessage = "";
	
	// *****************************************************
	// コンストラクタ
	// *****************************************************
	public LboxDatabase() {
		
		Initialize();
	
	}

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

	}

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

		DriverName = strName;

	}

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

		ConnectionUrl = strUrl;

	}

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

		ConnectionDbname = strUrl;

	}

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

		ConnectionUser = strUser;

	}

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

		ConnectionPass = strPass;

	}

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


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

			return true;
		}
		catch( ClassNotFoundException e ) {
			ErrorMessage = e.getMessage();
			return false;
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			return false;
		}

	}

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

		ErrorMessage = "";
		
		try {
			stmt.close();
			con.close();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

	}

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

		ErrorMessage = "";
		boolean bRet = true;

		try {
			rset = stmt.executeQuery ( Sql );
			bRet = rset.next();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			bRet = false;
		}

		return bRet;
	}
	public boolean Query()  {

		ErrorMessage = "";
		boolean bRet = true;

		try {
			bRet = rset.next();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			bRet = false;
		}

		return bRet;
	}

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

		ErrorMessage = "";
		String strResult = "";

		try {
			strResult = rset.getString( strName );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

		return strResult;
	}
	public String Fields( int nIndex ) {

		ErrorMessage = "";
		String strResult = "";

		try {
			strResult = rset.getString( nIndex );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

		return strResult;
	}

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

		ErrorMessage = "";

		int nRet;

		try {
			nRet = stmt.executeUpdate( Query );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			return -1;
		}

		return nRet;

	}

	// *****************************************************
	// データ一覧をコンボボックスにセット
	// *****************************************************
	public boolean LoadSqlData( LboxCombobox LCombo, String Query ) {

		boolean bRet;
		boolean bOk = false;
		String strData,strText;

		LCombo.byFuncton = true;
		
		LCombo.Reset();
		
		bRet = this.Query(Query);
		while( bRet ) {
			bOk = true;
			strData = this.Fields(1);
			strText = this.Fields(2);
			LCombo.Add(strData,strText);
			bRet = this.Query();
		}

		return bRet;

	}
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ