Category Archives: Coders

Docker cheat sheat

This is summary of docker command which you will often used, when you using docker:

Pulling images from docker hub

 docker pull [docker-repo-id]:[tag]

Running docker images as new container

docker run --name [container-id] [docker-repo-id]:[tag]

Listing running process on docker host

docker ps

See logs from a docker container process

docker logs -f [container-id]

Stopping docker container

docker stop [container-id]

Start docker container

docker start [container-id]

Enter to docker container to do shell scripting

docker exec -it [container-id] /bin/bash

Start docker images as new container with custom port

docker run -d -p [host-ip-port]:[docker-port] --name [container-id] [docker-repo-id]:[tag]

Remove docker container

docker container rm [container-id]

List all pulled images

docker image ls

Start docker container with docker-compose file

docker-compose -f [file-config.yml] up

Build custom images from other images with DockerFile

docker build -t [docker-repo-id]:[tag] .

HOW to install java on ubuntu

Installation Setup

1. Issue following command to find out current jdk version in apt-get

apt-cache search jdk

2. Choose what version do you want to Install, once you choose install java JDK and JRE with apt-get install

apt-get install sun-java6-jdk sun-java6-jre

3. Ubuntu will auto download necessary file from web for installation.

Do you want to continue [Y/n]? y
Get:1 http://my.archive.ubuntu.com hardy/main java-common 0.28ubuntu3 [78.2kB]
Get:2 http://my.archive.ubuntu.com hardy/multiverse sun-java6-jre 6-06-0ubuntu1 [6334kB]
Get:3 http://my.archive.ubuntu.com hardy/main odbcinst1debian1 2.2.11-16build1 [66.2kB]
Get:4 http://my.archive.ubuntu.com hardy/main unixodbc 2.2.11-16build1 [289kB]
Get:5 http://my.archive.ubuntu.com hardy/multiverse sun-java6-bin 6-06-0ubuntu1 [27.3MB]
Get:6 http://my.archive.ubuntu.com hardy/multiverse sun-java6-jdk 6-06-0ubuntu1 [9625kB]
85% [6 sun-java6-jdk 3208002/9625kB 33%]

4. After installation done, jdk and jre will install at /usr/lib/jvm/java-6-sun-1.6.0.06

5. Ubuntu help to create a java symbolic link, you can put it on /usr/bin for shortcut access

4. type java -version in terminal, DONE !!

Generate Java jaxb class from xsd using xjc

Starting on java 11 xjc was removed, so in order to use xjc you must install or download jdk1.8 then enter bin directory. After do all that step you can execute this command as an example :

xjc -p com.wordpress.nettako.java.generated -d C:\JaxbTest\src\main\java C:\JaxbTest\src\main\resources\xsd\employee.xsd

-p option indicate the package directory output

-d output folder

Switch Java Version On Current Batch File

Sometimes you want to run java program different on main default java in environment variable, this is the way you change or switch java version one to another

@echo off
:start
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_40
echo Setting PATH
set PATH=%PATH%;%JAVA_HOME%\bin
echo Display java version
java -version

output

Setting JAVA_HOME
Setting PATH
Display java version
java version “1.7.0_40”
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

another example

@echo off
:start
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk-11.0.7
echo Setting PATH
set PATH=%PATH%;%JAVA_HOME%\bin
echo Display java version
java -version

output

Setting JAVA_HOME
Setting PATH
Display java version
java version “11.0.7” 2020-04-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)

Add Maven External Jar File

Sometimes you want to include your own jar files to your pom.xml file

It is possible by adding, the jar file to your local .m2 folder, after you provide your own lib jar for example “Export_policy.jar”, execute below commad

mvn install:install-file \
-Dfile=Export_policy.jar \
-DgroupId=com.wordpress.nettako \
-DartifactId=export-policy \
-Dversion=1.8-RELEASAE \
-Dpackaging=jar

then write below example code in your pom.xml

<dependency>
   <groupId>com.wordpress.nettako</groupId>
   <artifactId>export-policy</artifactId>
   <version>1.8-RELEASE</version>
</dependency>

Done.

DB2 Cannot Alter Table Column Error code 12 Function No support

Pernah sekian waktu pada saat merubah kolom atau struktur tabel dihadapkan dengan error yang ada dijudul.

pusing berselancar di internet tidak menemukan solusi, semoga aja postingan ini bermanfaat.

Untuk kasus yang saya alami ternyata tabel yang akan saya ubah digunakan oleh tabel berjenis MQT di DB2.

MQT sendiri adalah sejenis tabel namun seperti view singkatnya seperti itu, cmiiw. mungkin mastah mastah yg baca post ini lebih manut mohon dikoreksi.

Dan MQT yang menggunakan tabel yg akan kita alter tinggal di drop dan di create ulang setelah kita melakukan alter tabel.

contoh drop MQT

DROP TABLE MQT_ASOY

lalu lakukan perubahan struktur data

ALTER TABLE ASOY_GEBOY ALTER COLUMN JOSGANDOS SET DATA TYPE VARCHAR(100)

create ulang mqt nya dan selesai deh

CREATE TABLE MQT_ASOY AS (

SELECT * FROM ASOY_GEBOY

) DATA INITIALLY DEFERRED REFRESH DEFERRED;

Database Linking Postgre in Ubuntu to SQL Server 2008 R2 in Windows

1.UBUNTU

Setting postgre /etc/postgresql/main/pg_hba.conf untuk mengizinkan (ALLOW) connection dari network ke local postgre.

file: pg_hba.conf

edit baris

#IPv4 local connections:
host         all           all                127.0.0.1/32      md5

jadi

#IPv4 local connections:
host        all            all               0.0.0.0/0            md5

kemudian pada dir yang sama edit file postgresql.conf

file: postgresql.conf

Ubah baris

#listen_addresses = ‘localhost’

menjadi

listen_addresses = ‘*’

Ubah baris

#password_encryption = on

menjadi

password_encryption = on

Jangan lupa matikan firewall pada linux. caranya pada ubuntu

sudo ufw disable

Untuk menyalakan kembali firewall, caranya

sudo ufw enable

2.WINDOWS

Download pgsql odbc terbaru di
http://www.postgresql.org/ftp/odbc/versions/msi/
install pgsql odbc.

buka administrative tools > ODBC. ikuti langkah-langkah berikut

Buka Microsoft SQL Server Management (MSSM), ikuti langkah-langkah berikut

Kemudian akan muncul wizard “New Linked Server”

Masukan data dan klik Ok untuk menyudahi. Pada database explorer expand folder Server Object > Linked Servers akan terdapat database yang terhubung pada ubuntu.

Jpa pool using tomcat 7 JDBC configuration

if you want to configure JDBC POOL  JPA within Tomcat app server, I have an example for this case.

  1. First you must edit context.xml, add the “Resource” tag.

file: context.xml

<Context antiJARLocking="true" path="/orchestra">
<Resource name="jdbc/dbsource" 
	      auth="Container" 
		  type="javax.sql.DataSource"
		  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
		  driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
		  username="sa" 
		  password="sa" 
		  url="jdbc:sqlserver://localhost:1433;databaseName=mydb;user=sa;password=sa;" 
		  testOnBorrow="true" 
		  validationQuery="SELECT 1" />
</Context>
  1. Link the “Resource” tag to your application, edit web.xml and add this line within the <web-app> tag

file: web.xml

<resource-ref>
	<description>DB Connection</description>
	<res-ref-name>jdbc/orchestra</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
</resource-ref>
  1. Create persistance.xml, copy this following code
<?xml version="1.0" encoding="UTF-8"?>
	<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="orchestraPU" transaction-type="JTA">
		<jta-data-source>java:/comp/env/jdbc/orchestra</jta-data-source>
		<exclude-unlisted-classes>false</exclude-unlisted-classes>
		<properties/>
	</persistence-unit>
</persistence>

Jurus Ampuh COPAS (Copy Paste) Tabel dengan SQL

Huah ngantuk, capeknya perjalanan pulang pergi kantor. Share apa nyak…okeh ini aja deh.

Buat yang penasaran gimanasih caranya ngopi tabel dari yang udah ada ke tabel baru pake SQL
, begindang caranya cyiiin.

SQL Server:

SELECT * INTO tabel_new
FROM tabel_existing

ORACLE:

CREATE TABLE tabel_new

AS SELECT * FROM tabel_existing

Dimana query SELECT * FROM tabel_existing bisa juga kita ganti dengan Query T-SQL pada lazimnya seperti SELECT JOIN, SELECT DISTINCT, dsb.