podman を用いて SQL Server を導入した際のメモ
podman を用いて Linux 版 SQL Server 環境を構築した際のメモを整理します。
(殆ど同じ会社の方に教えていただいた情報ですが…)
ここでは JBoss EAP から SQL Server へ接続する前提で環境を用意します。
インストーラを用いて Windows 版の SQL Server を導入するのは以前の会社でかなり実施しましたが、docker や podman を用いると1行のコマンドを実行するだけで SQL Server があっと言う間に導入できてしまうのに目から鱗でした。
あと、以下の Microsoft さんのページも参考になるかと思います。
Microsoft SQL Server by Microsoft | Docker Hub
- SQL Server コンテナイメージの入手/起動
$ podman run --name demo_mssql2019 -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<任意のパスワード>" mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-20.04
Trying to pull mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-20.04...
Getting image source signatures
Copying blob 2e5e63d166b4 done
Copying blob dc034f624aa1 done
Copying blob cafda714f10f done
Copying blob ea362f368469 done
Copying blob c6af4ce68233 done
Copying config d78e982c2f done
Writing manifest to image destination
Storing signatures
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
2022-08-08 07:03:06.61 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2022-08-08 07:03:06.82 Server Did not find an existing master data file /var/opt/mssql/data/master.mdf, copying the missing default master and other system database files. If you have moved the database location, but not moved the database files, startup may fail. To repair: shutdown SQL Server, move the master database to configured location, and restart.
2022-08-08 07:03:06.90 Server Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2022-08-08 07:03:06.94 Server Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'.
2022-08-08 07:03:06.99 Server Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2022-08-08 07:03:07.04 Server Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2022-08-08 07:03:07.10 Server Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'.
2022-08-08 07:03:07.16 Server Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf'.
2022-08-08 07:03:07.21 Server Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.ldf' to '/var/opt/mssql/data/model_replicatedmaster.ldf'.
2022-08-08 07:03:07.27 Server Setup step is FORCE copying system data file 'C:\templatedata\model_msdbdata.mdf' to '/var/opt/mssql/data/model_msdbdata.mdf'.
2022-08-08 07:03:07.33 Server Setup step is FORCE copying system data file 'C:\templatedata\model_msdblog.ldf' to '/var/opt/mssql/data/model_msdblog.ldf'.
2022-08-08 07:03:07.55 Server Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) - 15.0.4198.2 (X64)
Jan 12 2022 22:30:08
Copyright (C) 2019 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 20.04.3 LTS) <X64>
2022-08-08 07:03:07.59 Server UTC adjustment: 0:00
2022-08-08 07:03:07.61 Server (c) Microsoft Corporation.
2022-08-08 07:03:07.62 Server All rights reserved.
2022-08-08 07:03:07.64 Server Server process ID is 388.
2022-08-08 07:03:07.66 Server Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2022-08-08 07:03:07.69 Server Registry startup parameters:
-d /var/opt/mssql/data/master.mdf
-l /var/opt/mssql/data/mastlog.ldf
-e /var/opt/mssql/log/errorlog
2022-08-08 07:03:07.74 Server SQL Server detected 1 sockets with 6 cores per socket and 6 logical processors per socket, 6 total logical processors; using 6 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2022-08-08 07:03:07.81 Server SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2022-08-08 07:03:07.85 Server Detected 7957 MB of RAM. This is an informational message; no user action is required.
2022-08-08 07:03:07.92 Server Using conventional memory in the memory manager.
2022-08-08 07:03:07.98 Server Warning: Timer device resolution is greater than required. Required: 1. Found: 10.
2022-08-08 07:03:08.01 Server Page exclusion bitmap is enabled.
2022-08-08 07:03:08.09 Server Buffer pool extension is not supported on Linux platform.
2022-08-08 07:03:08.15 Server Buffer Pool: Allocating 2097152 bytes for 1050217 hashPages.
2022-08-08 07:03:08.98 Server Buffer pool extension is already disabled. No action is necessary.
2022-08-08 07:03:11.33 Server Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2022-08-08 07:03:11.50 Server Query Store settings initialized with enabled = 1,
2022-08-08 07:03:11.56 Server The maximum number of dedicated administrator connections for this instance is '1'
2022-08-08 07:03:11.56 Server Node configuration: node 0: CPU mask: 0x000000000000003f:0 Active CPU mask: 0x000000000000003f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2022-08-08 07:03:11.70 Server Using dynamic lock allocation. Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node. This is an informational message only. No user action is required.
2022-08-08 07:03:11.80 Server In-Memory OLTP initialized on lowend machine.
2022-08-08 07:03:11.91 Server CLR version v4.0.30319 loaded.
2022-08-08 07:03:11.92 Server [INFO] Created Extended Events session 'hkenginexesession'
2022-08-08 07:03:11.96 Server Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
ForceFlush is enabled for this instance.
2022-08-08 07:03:12.12 Server Total Log Writer threads: 2. This is an informational message; no user action is required.
2022-08-08 07:03:12.20 Server clflushopt is selected for pmem flush operation.
2022-08-08 07:03:12.23 Server Software Usage Metrics is disabled.
2022-08-08 07:03:12.32 spid9s [1]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:03:12.36 spid9s Starting up database 'master'.
ForceFlush feature is enabled for log durability.
2022-08-08 07:03:12.80 Server Common language runtime (CLR) functionality initialized.
2022-08-08 07:03:12.89 spid9s Converting database 'master' from version 897 to the current version 904.
2022-08-08 07:03:12.93 spid9s Database 'master' running the upgrade step from version 897 to version 898.
2022-08-08 07:03:12.97 spid9s Database 'master' running the upgrade step from version 898 to version 899.
2022-08-08 07:03:13.06 spid9s Database 'master' running the upgrade step from version 899 to version 900.
2022-08-08 07:03:13.14 spid9s Database 'master' running the upgrade step from version 900 to version 901.
2022-08-08 07:03:13.19 spid9s Database 'master' running the upgrade step from version 901 to version 902.
2022-08-08 07:03:13.25 spid9s Database 'master' running the upgrade step from version 902 to version 903.
2022-08-08 07:03:13.29 spid9s Database 'master' running the upgrade step from version 903 to version 904.
2022-08-08 07:03:13.79 spid9s Resource governor reconfiguration succeeded.
2022-08-08 07:03:13.83 spid9s SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2022-08-08 07:03:13.91 spid9s SQL Server Audit has started the audits. This is an informational message. No user action is required.
2022-08-08 07:03:14.09 spid9s SQL Trace ID 1 was started by login "sa".
2022-08-08 07:03:14.15 spid35s Password policy update was successful.
2022-08-08 07:03:14.20 spid9s Server name is 'aa665da98ac0'. This is an informational message only. No user action is required.
2022-08-08 07:03:14.36 spid37s Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2022-08-08 07:03:14.36 spid9s [4]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:03:14.37 spid12s [32767]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:03:14.46 spid37s Always On: The availability replica manager is waiting for the instance of SQL Server to allow client connections. This is an informational message only. No user action is required.
2022-08-08 07:03:14.48 spid9s Starting up database 'msdb'.
2022-08-08 07:03:14.56 spid12s Starting up database 'mssqlsystemresource'.
2022-08-08 07:03:14.64 spid35s A self-generated certificate was successfully loaded for encryption.
2022-08-08 07:03:14.78 spid12s The resource database build version is 15.00.4198. This is an informational message only. No user action is required.
2022-08-08 07:03:14.84 spid35s Server is listening on [ 'any' <ipv6> 1433].
2022-08-08 07:03:14.90 spid35s Server is listening on [ 'any' <ipv4> 1433].
2022-08-08 07:03:14.99 Server Server is listening on [ ::1 <ipv6> 1434].
2022-08-08 07:03:15.05 Server Server is listening on [ 127.0.0.1 <ipv4> 1434].
2022-08-08 07:03:15.09 Server Dedicated admin connection support was established for listening locally on port 1434.
2022-08-08 07:03:15.09 spid9s The tail of the log for database msdb is being rewritten to match the new sector size of 4096 bytes. 3072 bytes at offset 50176 in file /var/opt/mssql/data/MSDBLog.ldf will be written.
2022-08-08 07:03:15.14 spid12s [3]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:03:15.23 spid35s Server is listening on [ ::1 <ipv6> 1431].
2022-08-08 07:03:15.31 spid12s Starting up database 'model'.
2022-08-08 07:03:15.36 spid35s Server is listening on [ 127.0.0.1 <ipv4> 1431].
2022-08-08 07:03:15.42 spid35s SQL Server is now ready for client connections. This is an informational message; no user action is required.
2022-08-08 07:03:15.46 spid9s Converting database 'msdb' from version 897 to the current version 904.
2022-08-08 07:03:15.56 spid9s Database 'msdb' running the upgrade step from version 897 to version 898.
2022-08-08 07:03:15.61 spid12s The tail of the log for database model is being rewritten to match the new sector size of 4096 bytes. 512 bytes at offset 73216 in file /var/opt/mssql/data/modellog.ldf will be written.
2022-08-08 07:03:15.65 spid9s Database 'msdb' running the upgrade step from version 898 to version 899.
2022-08-08 07:03:15.78 spid9s Database 'msdb' running the upgrade step from version 899 to version 900.
2022-08-08 07:03:15.81 spid12s Converting database 'model' from version 897 to the current version 904.
2022-08-08 07:03:15.83 spid12s Database 'model' running the upgrade step from version 897 to version 898.
2022-08-08 07:03:15.87 spid9s Database 'msdb' running the upgrade step from version 900 to version 901.
2022-08-08 07:03:15.88 spid12s Database 'model' running the upgrade step from version 898 to version 899.
2022-08-08 07:03:15.94 spid9s Database 'msdb' running the upgrade step from version 901 to version 902.
2022-08-08 07:03:15.99 spid12s Database 'model' running the upgrade step from version 899 to version 900.
2022-08-08 07:03:16.06 spid12s Database 'model' running the upgrade step from version 900 to version 901.
2022-08-08 07:03:16.12 spid12s Database 'model' running the upgrade step from version 901 to version 902.
2022-08-08 07:03:16.17 spid12s Database 'model' running the upgrade step from version 902 to version 903.
2022-08-08 07:03:16.22 spid12s Database 'model' running the upgrade step from version 903 to version 904.
2022-08-08 07:03:16.43 spid12s Clearing tempdb database.
2022-08-08 07:03:16.74 spid12s [2]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:03:16.76 spid12s Starting up database 'tempdb'.
2022-08-08 07:03:17.00 spid12s The tempdb database has 1 data file(s).
2022-08-08 07:03:17.03 spid37s The Service Broker endpoint is in disabled or stopped state.
2022-08-08 07:03:17.08 spid37s The Database Mirroring endpoint is in disabled or stopped state.
2022-08-08 07:03:17.13 spid9s Database 'msdb' running the upgrade step from version 902 to version 903.
2022-08-08 07:03:17.15 spid37s Service Broker manager has started.
2022-08-08 07:03:17.18 spid9s Database 'msdb' running the upgrade step from version 903 to version 904.
2022-08-08 07:03:17.98 spid9s Recovery is complete. This is an informational message only. No user action is required.
2022-08-08 07:03:18.77 spid48s The default language (LCID 0) has been set for engine and full-text services.
2022-08-08 07:03:19.33 spid48s The tempdb database has 6 data file(s).
2022-08-08 07:08:22.57 spid56 [5]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-08-08 07:08:22.59 spid56 Starting up database 'test'.
2022-08-08 07:08:22.66 spid56 Parallel redo is started for database 'test' with worker pool size [3].
2022-08-08 07:08:22.77 spid56 Parallel redo is shutdown for database 'test' with worker pool size [3].
2022-08-08 07:09:57.96 spid59 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2022-08-08 07:09:58.07 spid59 Using 'xplog70.dll' version '2019.150.4198' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.
- SQL Server が起動したら他の端末から sqlcmd を起動し、動作確認用の test データベースを作成
$ podman exec -it demo_mssql2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <指定したパスワード>
1> create database test
2> go
1> SELECT name, database_id, create_date FROM sys.databases
2> go
name database_id create_date
-------------------------------------------------------------------------------------------------------------------------------- ----------- -----------------------
master 1 2003-04-08 09:13:36.390
tempdb 2 2022-08-08 07:03:17.027
model 3 2003-04-08 09:13:36.390
msdb 4 2022-01-12 22:54:24.927
test 5 2022-08-08 07:08:22.333
(5 rows affected)
- test データベースへ切り替えて、動作確認用の book テーブルを作成
(補足)ここでは book テーブルは利用していないため、この手順は省略可能です。
1> use test
2> go
Changed database context to 'test'.
2> CREATE TABLE Book (id INT PRIMARY KEY, title varchar(100), author varchar(100))
3> go
1> select * from book
2> go
id title author
----------- ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
(0 rows affected)
1> quit
$
- 以下のページより SQL Server 用 JDBC ドライバ(Microsoft JDBC Driver 10.2 for SQL Server)を入手
ダウンロードした zip ファイルを任意のディレクトリで展開し、以下の jar ファイルを任意のディレクトリ(/usr/share/javaなど)へコピー
mssql-jdbc-10.2.1.jre11.jar
mssql-jdbc-10.2.1.jre17.jar
mssql-jdbc-10.2.1.jre8.jar
- JBoss EAP の CLI から SQL Server 用 JDBC ドライバモジュールをコアモジュールとして導入(dependenciesパラメータが正しくないかも…)
(補足)以下の手順では Java 11 用の JDBC ドライバを登録していますが、環境に応じて読み替えてください。
$JBOSS_HOME/bin/jboss-cli.sh -c
[standalone@localhost:9990 /] module add --name=com.microsoft --resources=/usr/share/java/mssql-jdbc-10.2.1.jre11.jar --dependencies=javaee.api,sun.jdk,ibm.jdk,javax.api,javax.transaction.api
[standalone@localhost:9990 /] quit
- JBoss EAP の standalone.xml の datasource 定義へ以下のように SQL Server に関する定義を追加
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
--- 省略 ---
<datasource jndi-name="java:jboss/datasources/MsSQLDS" pool-name="MsSQLDS">
<connection-url>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test;trustServerCertificate=true</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<initial-pool-size>10</initial-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>sa</user-name>
<password><指定したパスワード></password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
<validate-on-match>true</validate-on-match>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
--- 省略 ---
<driver name="sqlserver" module="com.microsoft">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
- JBoss EAP を起動し、SQL Server と接続されていることを確認
$ netstat -na | grep 1433
tcp 0 0 127.0.0.1:58894 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58852 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:52956 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58858 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58880 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58842 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:52978 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58872 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58850 127.0.0.1:1433 ESTABLISHED
tcp 0 0 127.0.0.1:58890 127.0.0.1:1433 ESTABLISHED
tcp6 0 0 :::1433 :::* LISTEN
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58872 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58858 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:52978 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58894 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58852 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58880 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:52956 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58850 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58890 ESTABLISHED
tcp6 0 0 127.0.0.1:1433 127.0.0.1:58842 ESTABLISHED
$
以上で JBoss EAP + SQL Server の環境が構築できました。
- SQL Server コンテナイメージの起動
$ podman start demo_mssql2019
demo_mssql2019
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aa665da98ac0 mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-20.04 /opt/mssql/bin/sq... 17 hours ago Up 10 seconds ago 0.0.0.0:1433->1433/tcp demo_mssql2019
$
- SQL Server コンテナイメージの停止(一例)
$ podman exec -it demo_mssql2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <指定したパスワード>
1> shutdown
2> go
Server shut down by request from login sa.
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$
今後の作業として、時間がある時に Blue Prism のリポジトリ DB として Linux 版 SQL Server が利用可能か検証してみたいなと思います。(動作したとしてもサポート外の構成ですが…)
Lenovo ThinkPad トラックポイント キーボードを購入してみました
会社から支給されてる PC は英語配列キーボードで自分にはしっくりこないため、日本語配列の Lenovo ThinkPad トラックポイント キーボードを購入してみました。
他にも OpenShift local を検証するために購入した ThinkCentre もあるので、USB ドングル(会社PC)と Bluetooth(ThinkCentre)でそれぞれの PC へ接続して利用しております。
今までは MOBO Keyboard2 を利用していて、こちらも折り畳むことが出来てとても良いキーボードだったのですが、ThinkPad トラックポイント キーボードは名前通りトラックポイントが利用できるので両手をホームポジションに置いたままでかなりの作業を実施することが可能となりました。
それでもマウスを使うことはあるため、マルチペアリングが可能な iClever のマウスも購入し、3台の PC を切り換えて操作可能な環境を構築しました。このマウスは PC 切替時の反応が良いためストレスなく切り替えができるので購入して良かったと感じています。
今まで利用していた MOBO Keyboard2 はとてもコンパクトなので出社時にオフィスで利用しようと思います。(現時点で出社の予定はないですが…)
<< 追記 >>
Fn キーと Ctrl キーを入れ替えたかったのでいろいろ調べたのですが、外付けキーボードとしてはそのような対応は出来ないようでした。残念。
<< 更に追記 >>
中央ボタンを押しながらポインティングデバイスを操作すると画面がスクロール可能なのですが、中央ボタンのみをクリックしてしまうとマウスの真ん中ボタンをクリックした時と同様にクリップボードの内容が張り付いてしまうことに気づき、不用意に仕事関係のファイルを編集してしまう可能性を危惧して MOBO Keyboard2 に戻すことにしました。
恐らく利用するのが Windows PC のみなら中央ボタンの割り当てをもう少し調整できたかも知れませんが、今の仕事は Linux PC がメインなので諦めました。仕事を引退して自分のファイルしか触らなくなったら ThinkPad トラックポイント キーボードに戻そうかな。(いったいいつになるやら…)
Linux で画面ロックを無効にしても画面がロックされてしまう場合の対処
自分のメイン PC は会社から支給された Red Hat Enterprise Linux 8.6 環境なのですが、セキュリティポリシーのためか画面ロックを無効にすることができないため、10分間放置すると画面がロックされてしまいます。
在宅勤務で私以外に Linux PC に触れる人はないために画面ロックが行われないようにしたかったのですが、以下のページを参考に xdotool と言うツールを導入することで対処することが出来ました。
手順としては凄く簡単で、以下のような感じです。
- xdotool をインストール
sudo dnf install xdotool
- 以下のようなシェルスクリプトを用意
#!/bin/bash
while [ true ]
do
xdotool mousemove_relative 1 1
sleep 590
xdotool mousemove_relative -- -1 -1
sleep 590
done
(補足) 10分(600秒) より少し短いタイミングでマウスカーソルを1ドット右下へ移動したり、右上へ戻したりしています。
あとは、暫くLinux PC に触れないけど画面更新だけは見ていたい場合に上記スクリプトを実行するだけです。 (自分の環境では2時間以上画面ロックが行われないことは確認できました)
10分くらいに一度だけマウスカーソルが1ドットずれるだけなので Linux PC 上で作業中にこのスクリプトを実行したままでも問題ないのかなと予想しております。
(追記)上記スクリプトを実行しながら1日 Linux PC に触れましたが特に問題もなく、食事などで10分以上離席しても画面がロックされることはなかったです。
ちなみに、このノウハウは前職の RPA ベンダーに居た頃に RPA 製品で画面ロックを無効にするようなシナリオも作れたため、その経験をベースに xdotool を試してみたところ上手くいきました。
<< 追記 >>
この対処方法は自分としてはメチャクチャ活用できていて、ちょっとしたスクリプトですが、会社 PC を放置しても勝手に画面がロックされなくなりました。 ただ、オフィスなどでこの対応してしまうとセキュリティ的に不味いので自宅専用ソリューションとしてご利用ください。
podman を用いた環境構築後に Oracle DB の動作確認を実施した際のメモ
podman を用いた環境構築後に Oracle DB の動作確認を実施した際のメモを整理します。
$ podman exec -it test_oracle bash
bash-4.2$
bash-4.2$ export NLS_LANG=Japanese_Japan.AL32UTF8
bash-4.2$
bash-4.2$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 金 7月 29 10:20:47 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
に接続されました。
SQL>
SQL> select name from v$pdbs;
NAME
--------------------------------------------------------------------------------
PDB$SEED
ORCLPDB1
SQL>
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
SQL> alter session set container = orclpdb1;
セッションが変更されました。
SQL>
- PDB 上で demo_user ユーザーを作成し、簡単なテーブルを用いた動作確認を実施
SQL> create user demo_user identified by <任意のパスワードを指定> default tablespace users temporary tablespace temp;
ユーザーが作成されました。
SQL>
SQL> grant connect, resource to demo_user;
権限付与が成功しました。
SQL>
SQL> create table aaa ( bbb varchar2(100), ccc varchar2(100) );
表が作成されました。
SQL>
SQL> insert into aaa values ( 'TEST0001', 'テスト0001' );
1行が作成されました。
SQL>
SQL> commit;
コミットが完了しました。
SQL>
SQL> select * from aaa;
BBB
--------------------------------------------------------------------------------
CCC
--------------------------------------------------------------------------------
TEST0001
テスト0001
SQL>
SQL> quit
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0との接続が切断されました。
bash-4.2$
- 改めて SQL*Plus から再度ログインし、動作を確認
bash-4.2$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on 金 7月 29 10:26:58 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
に接続されました。
SQL>
SQL> alter session set container = orclpdb1;
セッションが変更されました。
SQL>
SQL> select * from aaa;
BBB
--------------------------------------------------------------------------------
CCC
--------------------------------------------------------------------------------
TEST0001
テスト0001
SQL>
SQL>
SQL> quit
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0との接続が切断されました。
bash-4.2$
これまでの3回の投稿で、podman を用いて Oracle DB を構築し、簡単な動作確認を実施した流れが整理できました。
これらの情報が何かしら参考になれば幸いです。
podman を用いた環境構築後に Oracle DB 環境を起動/停止した際のメモ
podman を用いた環境構築後に Oracle DB 環境を起動/停止した際のメモを整理します。
- Oralce DB の起動
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93b06e918504 container-registry.oracle.com/database/enterprise:19.3.0.0 /bin/sh -c exec $... 2 weeks ago Exited (137) 2 weeks ago 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp test_oracle
$
$ podman start test_oracle
test_oracle
- SQL*Plus からログイン可能なことを確認
$ podman exec -it test_oracle bash
bash-4.2$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 29 01:28:06 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>
SQL> quit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
bash-4.2$
bash-4.2$ exit
- Oralce DB の停止
$ podman exec -it test_oracle bash
bash-4.2$
bash-4.2$ lsnrctl stop
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-JUL-2022 01:28:26
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
bash-4.2$
bash-4.2$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 29-JUL-2022 01:28:31
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 2: No such file or directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
bash-4.2$
bash-4.2$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 29 01:28:44 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
bash-4.2$ exit
$
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93b06e918504 container-registry.oracle.com/database/enterprise:19.3.0.0 /bin/sh -c exec $... 2 weeks ago Up 2 minutes ago (starting) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp test_oracle
$
$ podman stop test_oracle
test_oracle
$
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
podman を用いた環境構築後に Oracle DB の動作確認を実施した際のメモは後程整理します。
podman を用いて Oracle DB 環境を作成した際のメモ
podman を用いて Oracle DB 環境を作成した際のメモを整理します。
podman login container-registry.oracle.com
Username: <My Oracle Supportのユーザー名>
Password: <My Oracle Supportのパスワード>
- Oracle DB コンテナイメージを pull
podman pull container-registry.oracle.com/database/enterprise:19.3.0.0
podman run --name test_oracle -p 1521:1521 -p 5500:5500 -e ORACLE_PWD=<任意をパスワードを指定> -e ORACLE_EDITION=enterprise container-registry.oracle.com/database/enterprise:19.3.0.0
ORACLE EDITION: ENTERPRISE
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 12-JUL-2022 23:02:36
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/93b06e918504/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 12-JUL-2022 23:02:37
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/93b06e918504/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
[WARNING] [DBT-06208] The 'SYS' password entered does not conform to the Oracle recommended standards.
CAUSE:
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'SYSTEM' password entered does not conform to the Oracle recommended standards.
CAUSE:
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'PDBADMIN' password entered does not conform to the Oracle recommended standards.
CAUSE:
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details.
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Jul 12 23:16:04 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>
System altered.
SQL>
System altered.
SQL>
Pluggable database altered.
SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
Session altered.
SQL>
User created.
SQL>
Grant succeeded.
SQL>
Grant succeeded.
SQL>
Grant succeeded.
SQL>
User altered.
SQL> SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
Executing user defined scripts
/opt/oracle/runUserScripts.sh: running /opt/oracle/scripts/extensions/setup/savePatchSummary.sh
/opt/oracle/runUserScripts.sh: running /opt/oracle/scripts/extensions/setup/swapLocks.sh
DONE: Executing user defined scripts
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
Executing user defined scripts
/opt/oracle/runUserScripts.sh: running /opt/oracle/scripts/extensions/startup/runDatapatch.sh
Datafiles are already patched. Skipping datapatch run.
DONE: Executing user defined scripts
The following output is now a tail of the alert.log:
ORCLPDB1(3):
ORCLPDB1(3):XDB initialized.
2022-07-12T23:16:04.889663+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
2022-07-12T23:16:04.897846+00:00
ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed: ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
XDB initialized.
2022-07-12T23:25:53.405154+00:00
ORCLPDB1(3):Resize operation completed for file# 10, old size 327680K, new size 337920K
2022-07-13T00:01:01.155536+00:00
TABLE SYS.WRP$_REPORTS_TIME_BANDS: ADDED INTERVAL PARTITION SYS_P190 (4576) VALUES LESS THAN (TO_DATE(' 2022-07-13 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
2022-07-13T00:06:02.219687+00:00
Resize operation completed for file# 3, old size 522240K, new size 532480K
2022-07-13T01:01:15.201398+00:00
TABLE SYS.WRP$_REPORTS: ADDED INTERVAL PARTITION SYS_P191 (4577) VALUES LESS THAN (TO_DATE(' 2022-07-14 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRP$_REPORTS_DETAILS: ADDED INTERVAL PARTITION SYS_P192 (4577) VALUES LESS THAN (TO_DATE(' 2022-07-14 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
2022-07-13T01:06:16.300744+00:00
Resize operation completed for file# 3, old size 532480K, new size 542720K
2022-07-13T05:00:00.005421+00:00
ORCLPDB1(3):Setting Resource Manager plan SCHEDULER[0x4D50]:DEFAULT_MAINTENANCE_PLAN via scheduler window
ORCLPDB1(3):Setting Resource Manager plan DEFAULT_MAINTENANCE_PLAN via parameter
2022-07-13T05:00:04.575174+00:00
ORCLPDB1(3):TABLE SYS.WRI$_OPTSTAT_HISTHEAD_HISTORY: ADDED INTERVAL PARTITION SYS_P225 (44754) VALUES LESS THAN (TO_DATE(' 2022-07-14 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
ORCLPDB1(3):TABLE SYS.WRI$_OPTSTAT_HISTGRM_HISTORY: ADDED INTERVAL PARTITION SYS_P228 (44754) VALUES LESS THAN (TO_DATE(' 2022-07-14 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
2022-07-13T05:00:13.875028+00:00
Thread 1 advanced to log sequence 9 (LGWR switch)
Current log# 3 seq# 9 mem# 0: /opt/oracle/oradata/ORCLCDB/redo03.log
2022-07-13T05:07:12.630864+00:00
Resize operation completed for file# 3, old size 542720K, new size 563200K
2022-07-13T05:07:12.631810+00:00
ORCLPDB1(3):Resize operation completed for file# 10, old size 337920K, new size 348160K
2022-07-13T06:07:26.760710+00:00
Resize operation completed for file# 3, old size 563200K, new size 573440K
2022-07-13T09:00:00.125817+00:00
ORCLPDB1(3):Closing scheduler window
ORCLPDB1(3):Closing Resource Manager plan via scheduler window
ORCLPDB1(3):Clearing Resource Manager plan via parameter
2022-07-13T09:00:07.668816+00:00
TABLE SYS.WRI$_OPTSTAT_HISTHEAD_HISTORY: ADDED INTERVAL PARTITION SYS_P195 (44754) VALUES LESS THAN (TO_DATE(' 2022-07-14 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRI$_OPTSTAT_HISTGRM_HISTORY: ADDED INTERVAL PARTITION SYS_P198 (44754) VALUES LESS THAN (TO_DATE(' 2022-07-14 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
- 別の端末から Oracle DB のシャットダウンを実施した際のログメッセージ
2022-07-13T11:05:51.784908+00:00
Shutting down ORACLE instance (normal) (OS id: 26438)
Stopping background process SMCO
2022-07-13T11:05:53.050505+00:00
Shutting down instance: further logons disabled
2022-07-13T11:05:53.131450+00:00
Stopping background process CJQ0
Stopping background process MMNL
2022-07-13T11:05:54.157173+00:00
Stopping background process MMON
2022-07-13T11:05:56.205966+00:00
alter pluggable database all close
2022-07-13T11:05:56.208116+00:00
ORCLPDB1(3):JIT: pid 26438 requesting stop
ORCLPDB1(3):Buffer Cache flush deferred for PDB 3
Pluggable database ORCLPDB1 closed
Completed: alter pluggable database all close
PDB$SEED(2):JIT: pid 26438 requesting stop
PDB$SEED(2):Buffer Cache flush deferred for PDB 2
License high water mark = 18
Dispatchers and shared servers shutdown
Data Pump shutdown on PDB: 1 in progress
ALTER DATABASE CLOSE NORMAL
Stopping Emon pool
Stopping background process AQPC
2022-07-13T11:05:57.997289+00:00
alter pluggable database all close
Completed: alter pluggable database all close
2022-07-13T11:05:58.999399+00:00
IM on ADG: Start of Empty Journal
IM on ADG: End of Empty Journal
Stopping Emon pool
stopping change tracking
2022-07-13T11:05:59.125624+00:00
Shutting down archive processes
2022-07-13T11:05:59.125760+00:00
TT00 (PID:2810): Gap Manager exiting
2022-07-13T11:06:00.126030+00:00
Archiving is disabled
2022-07-13T11:06:00.126439+00:00
Thread 1 closed at log sequence 9
Successful close of redo thread 1
2022-07-13T11:06:00.137324+00:00
Buffer Cache invalidation for all PDBs started
Buffer Cache invalidation for all PDBs complete
Completed: ALTER DATABASE CLOSE NORMAL
ALTER DATABASE DISMOUNT
Shutting down archive processes
Archiving is disabled
Completed: ALTER DATABASE DISMOUNT
2022-07-13T11:06:01.453858+00:00
.... (PID:26438): Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
2022-07-13T11:06:02.454984+00:00
JIT: pid 26438 requesting stop
.... (PID:26438): Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
JIT: pid 26438 requesting stop
2022-07-13T11:06:02.466759+00:00
Stopping background process VKTM
2022-07-13T11:06:12.241842+00:00
Instance shutdown complete (OS id: 26438)
podman を用いた環境構築後に Oracle DB 環境を起動/停止した際のメモは後程整理します。
JBoss EAP と PostgreSQL を接続した際のメモ
JBoss EAP と PostgreSQL を接続した際のメモを整理します。
以下のページを参考に PostgreSQL を導入
- Fedora 34 : PostgreSQL 13 : インストール
(補足)導入、初期設定、各コマンドなどについて簡潔に整理されていて参考になりました。
(補足)ここではデータベース名 : demo、ユーザー名 : demo_user を指定しています。
- Fedora 34 : PostgreSQL 13 : インストール
以下のページを参考に認証関連を変更
- PostgreSQLの設定 - 初めてのVPS構築
(補足)パスワード認証の METHOD を md5 に変更する手順が参考になりました。
- PostgreSQLの設定 - 初めてのVPS構築
パスワード認証を許可するためには、以下のようにMETHODをmd5に変更します。
# tail /var/lib/pgsql/data/pg_hba.conf
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
- psql で PostgreSQL へログイン
$ psql -U demo_user -h localhost -d demo
ユーザ demo_user のパスワード:
psql (13.6)
SSL 接続 (プロトコル: TLSv1.3、暗号化方式: TLS_AES_256_GCM_SHA384、ビット長: 256、圧縮: オフ)
"help"でヘルプを表示します。
demo=>
(補足)上記環境は SSL を有効にしています。
- テスト用 DB を作成し、検索が可能なことを確認 (超適当な SQL 文ですが…)
create table aaa ( bbb varchar(100), ccc varchar(100) );
insert into aaa values ( '0001', 'テスト0001' );
select * from aaa;
\q
以下から PostgreSQL JDBC ドライバを入手し、任意の場所へ配置する
PostgreSQL JDBC Download
(補足)この後の作業は以下のマニュアルが参考になります。12.15.3. PostgreSQL データソースの例 Red Hat JBoss Enterprise Application Platform 7.4
- JDBC ドライバをコアモジュールとして導入
module add --name=com.postgresql --resources=/usr/share/java/postgresql-42.4.0.jar --dependencies=javaee.api,sun.jdk,ibm.jdk,javax.api,javax.transaction.api
(補足)上記例では入手した JDBC ドライバを /usr/share/java へ配置しています。
- JDBC ドライバを登録
/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=com.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
- データソースを作成
data-source add --name=PostgresDS --jndi-name=java:jboss/PostgresDS --driver-name=postgresql --connection-url=jdbc:postgresql://localhost:5432/demo --user-name=demo_user --password=<demo_userのパスワード> --validate-on-match=true --background-validation=false --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
- 以下のような JSP を用意して PostgreSQL から検索が可能なことを確認
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jdbc postgresql demo</title>
</head>
<body>
<%
Context ctx = null;
DataSource ds = null;
Connection con = null;
Statement stmt = null;
ResultSet rset = null;
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:jboss/PostgresDS");
con = ds.getConnection();
stmt = con.createStatement();
rset = stmt.executeQuery("SELECT bbb,ccc FROM aaa");
while(rset.next()){
out.println("SQL実行結果 : " + rset.getString("CCC"));
}
try { rset.close(); } catch (Exception ignore) {}
try { stmt.close(); } catch (Exception ignore) {}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>
- JSP へアクセスし、以下の画面が表示されることを確認
SQL実行結果 : テスト0001
上記手順が何かしら参考になれば幸いです。