Search This Blog
2020/12/13
How To Install Oracle Java 14 on Ubuntu 20.04
Now run
sudo dpkg -i jdk-14_linux-x64_bin.deb
After this set the path to the Oracle Java executable
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.2/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-14.0.2/bin/javac 1
Choose from openjdk & oracle jdk
sudo update-alternatives --config java
Output
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/jdk-14.0.2/bin/java 1 manual mode
choose option number 2.
Now
sudo update-alternatives --config javac
Output:
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
* 2 /usr/lib/jvm/jdk-14.0.2/bin/javac 1 manual mode
Choose option number 2.
Now See which is your default JDK
java --version
output :
java 14.0.2 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
Setting JAVA_HOME enviornment variable
Run
sudo update-alternatives --config java
output:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
* 2 /usr/lib/jvm/jdk-14.0.2/bin/java 1 manual mode
from here correct java path is "/usr/lib/jvm/jdk-14.0.2/bin/java"
so the enviornment variable will be
JAVA_HOME="/usr/lib/jvm/jdk-14.0.2"
Open /etc/environment and add above line,
Now to reload enviornment variables run
source /etc/environment
2020/12/11
Working With GridView in Gambas using postgreSQL Database
In Gambas design a Form as Below, I am adding a TextBox,A command Button and a gridview.
Create a database table as follows
CREATE TABLE public.xproducts
(
id integer NOT NULL DEFAULT nextval('"Products_id_seq"'::regclass),
name character varying(50) COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "Products_pkey" PRIMARY KEY (id)
)
inside code behind I wrote a function for initialization of database connection
Public Procedure Connect()
$Con.Close() ' Close the connection
$Con.Type = "postgresql" ' Type of connection
$Con.Host = "localhost" ' Name of the server
$Con.Login = "xdba" ' User's name for the connection
$Con.Port = "5432" ' Port to use in the connection, usually 3306
$Con.Name = "sangram" ' Name of the database we want to use
$Con.Password = "sangram" ' User's password
$Con.Open() ' Open the connection
End
Now we will write a subroutine for populating Gridview
Public Sub LoadAll()
Dim $Result As Result
Dim $Field As ResultField
Dim $rowCount As Integer = 0
Dim $Query As String
$Query = "SELECT * FROM xproducts"
Connect()
$Result = FMain.$Con.Exec($Query)
'define layout
'define the gridview layout
GridView1.header = GridView.Horizontal
GridView1.grid = True
GridView1.Rows.count = $Result.Count + 1
GridView1.Columns.count = 2
'column headers
GridView1.Columns[0].text = "Id"
GridView1.Columns[1].text = "Name"
'column width
GridView1.Columns[0].width = 100
GridView1.Columns[1].width = 100
For Each $Result
GridView1[$rowCount, 0].Text = $Result!id
GridView1[$rowCount, 1].Text = $Result!name
'Message.Info($Result!id & " " & $Result!name)
$rowCount = $rowCount + 1
Next
End
On Click of Button wrote code to Insert record into database as follows
Public Sub BtnSave_Click()
Dim $Result As Result
Dim $name As String
Dim $Product As String
$name = TxtName.Text
Dim $Query As String
$Query = "INSERT INTO XProducts(name)VALUES('" & $name & "')"
Connect()
$Result = FMain.$Con.Exec($Query)
LoadAll
End
Here $Con is connection defined globally outside of all subroutines as follows
Public $Con As New Connection
In Button Click event handler we are inserting record & then populate gridview with all records.
To load gridview at page load I am doing following
Public Sub Form_Open()
LoadAll()
End
When we run our project Form looks like below
Code sample for this project can be viewed at
https://github.com/gitsangramdesai/gambas-pg-gridview.

