0

サーバーテーブルにサーバー名に関する情報が含まれるスタースキーマモデルがあります。情報テーブルには、特定のサーバーに必要な情報が含まれています。実際のデータテーブルには、どのサーバーにどの情報が含まれているかに関する情報が含まれています。

Server Table

ここに画像の説明を入力

Information Table

ここに画像の説明を入力

Actual Data Table

ここに画像の説明を入力

今私が抱えている問題は、JDBCを使用してデータをデータテーブルに挿入しようとしていることです。しかし、スター スキーマ モデルの実際のデータ テーブルにデータを追加する方法がわかりません。データベースに接続して情報ごとに毎回挿入する必要がありますか、またはデータベースと一度だけ通信することでそれを行うことができる直接的な方法があります。これは、各サーバーのすべての情報を取得するコードです。IndexData は、Oracle データベースに値を挿入するクラスです。

    public void fetchlog() {
            InputStream is = null;
            InputStream isUrl = null;
            FileOutputStream fos = null;
            try {
                is = HttpUtil.getFile(monitorUrl);
                if(monitorUrl.contains("stats.jsp") || monitorUrl.contains("monitor.jsp")) {
                    trimUrl = monitorUrl.replaceAll("(?<=/)(stats|monitor).jsp$", "ping");
                }
                isUrl = HttpUtil.getFile(trimUrl);
                BufferedReader in   = new BufferedReader (new InputStreamReader (is));
            String line;
            int i=0,j=0,k=0;
            while ((line = in.readLine()) != null) {
                if(line.contains("numDocs")) {
                    docs = in.readLine().trim();
    //So should I keep on inserting into Database for each information, like this
     //IndexData id = new IndexData(timeStamp, ServerName, InformationName, docs);
                }  else if(line.contains("indexSize")) {
                    indexSize = in.readLine().trim();
    //For this information-- the same way?
    //IndexData id = new IndexData(timeStamp, ServerName, InformationName, indexSize);
                } else if(line.contains("cumulative_lookups")) {
                    cacheHits= in.readLine().trim();
    //For this information too-- the same way?
    //IndexData id = new IndexData(timeStamp, ServerName, InformationName, cacheHits);
                } else if(line.contains("lastCommitTime")) {
                    lastCommitTime = in.readLine().trim();     
    //For this information too-- the same way?
    //IndexData id = new IndexData(timeStamp, ServerName, InformationName, lastCommitTime );

            }

            BufferedReader inUrl   = new BufferedReader (new InputStreamReader (isUrl));
            String lineUrl;
            Pattern regex = Pattern.compile("<str name=\"status\">(.*?)</str>");

            while ((lineUrl = inUrl.readLine()) != null) {
                System.out.println(lineUrl);
                if(lineUrl.contains("str name=\"status\"")) {
                    Matcher regexMatcher = regex.matcher(lineUrl);
                    if (regexMatcher.find()) {
                        upDown= regexMatcher.group(1);
//For this information too-- the same way?
    //IndexData id = new IndexData(timeStamp, ServerName, InformationName, upDown);

                    }                   
                     System.out.println("Status:- " + status);                  
                }  
            }
    //Or is there some other way we can insert directly into database by communicating with database only one time not multiple times for each information.     
            //IndexData id = new IndexData(timeStamp, ServerName, InformationName, Value);
                fos = new FileOutputStream(buildTargetPath());
                IOUtils.copy(is, fos);
            } catch (FileNotFoundException e) {
                log.error("File Exception in fetching monitor logs :" + e);
            } catch (IOException e) {
                log.error("Exception in fetching monitor logs :" + e);
            }
        }

I hope question is clear to everyone. Any suggestions will be appreciated.
4

1 に答える 1

4

見ていただきたいことが2つあります。まず、バッチ挿入を使用して、関連するすべての挿入を 1 つの JDBC トランザクションで実行します。詳細については:

JDBC バッチ挿入の例

また、JDBC 接続プール ライブラリを使用することを強くお勧めします。Postgres データベースで c3p0 を使用します。詳細については、次を参照してください。

c3p0 プロジェクトページ

基本的な考え方は、起動時に接続プールを作成し、関連する挿入のセットごとに JDBC バッチを作成することです。

于 2011-11-14T21:38:39.237 に答える