Minggu, 23 September 2012
PostgreSQL: Invalid byte sequence for encoding UTF8
I have a comma delimited file (.csv) contains stock master data and wanto to import them into PostgreSQL table .During importing, I am facing Invalid byte sequence for encoding "UTF8" error message.
C:\>psql -Umyname -dmydb -p5490
--1. do import
mydb=# \copy myshema.stocks from C:\temp\inv.csv with delimiter as ';'csv
ERROR: Invalid byte sequence for encoding "UTF8": 0xa0
CONTEXT: copy stock, line 26120
--2. check my client encoding
mydb=# show client_encoding;
client_encoding
----------------
UTF8
(1 row)
--3. modify my client encoding
mydb=# \client_encoding LATIN1
--3a. check current client encoding
mydb=# show client_encoding;
client_encoding
----------------
LATIN1
(1 row)
--4. Re do importing
mydb=# \copy myshema.stocks from C:\temp\inv.csv with delimiter as ';'csv
--5. reset client_encoding;
That is it.
Kamis, 20 September 2012
Create a Control to act like a Button
System.Windows.Forms.UserControl provides an empty control that can be used to create other controls. We might consider to inherit the class to create a control with custom appearance, feature and behaviour.
I then create a control that functionally same as standard button, but my control could not be be assign to AcceptButton and CancelButton property of a form. To allows the control to act like a button on a form, just implement the IButtonControl interface to the control.
public class FerBtn : System.Windows.Forms.UserControl, System.Windows.Forms.IButtonControl
{
}
After visit this, I copy and paste the DialogResult property, the NotifyDefault and PerformClick methods, and add a definition for IsDefault.
private bool mIsDefault;
[Browsable(false)]
public bool IsDefault
{
get { return this.mIsDefault; }
set { this.mIsDefault = value; }
}
Now this control could be assign to AcceptButton and CancelButton property of a form.
I then create a control that functionally same as standard button, but my control could not be be assign to AcceptButton and CancelButton property of a form. To allows the control to act like a button on a form, just implement the IButtonControl interface to the control.
public class FerBtn : System.Windows.Forms.UserControl, System.Windows.Forms.IButtonControl
{
}
After visit this, I copy and paste the DialogResult property, the NotifyDefault and PerformClick methods, and add a definition for IsDefault.
private bool mIsDefault;
[Browsable(false)]
public bool IsDefault
{
get { return this.mIsDefault; }
set { this.mIsDefault = value; }
}
Now this control could be assign to AcceptButton and CancelButton property of a form.
Selasa, 18 September 2012
To Get Distinct Rows By specific columns
My purpose today is to get the rows with unique data based on criteria of uniqueness value on the column, including combinations of column. As you may think, just use the DISTINCT clause. You are right! Let's try with PostgreSQL.
Firt, list the data using this statement:
SELECT a.nik, a.nama, g.ket as job, h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
=========================================================
nik nama job akunno alokasi
=========================================================
100.200 ALBERT Manajer 400 0.00
100.300 JHONI Danru Satpam 423 1.00
100.400 ZAENAL Anggota Satpam 423 1.00
100.500 ROBI Anggota Satpam 423 1.00
200.400 TEDDY Operator St. Kempa 603.07 0.40
200.400 TEDDY Operator St. Kempa 603.08 0.40
200.400 TEDDY Operator St. Kempa 603.09 0.20
300.500 JOKO Operator Kolam Limbah 603.11 0.50
300.500 JOKO Operator Kolam Limbah 603.12 0.50
300.650 SEPTIAN Operator St. Kempa 603.09 0.20
300.650 SEPTIAN Operator St. Kempa 603.07 0.40
300.650 SEPTIAN Operator St. Kempa 603.08 0.40
400.600 OPA OPO Kerani I TUK 401 1.00
----------------------------------------------------------
DISTINCT
DISTINCT will remove all duplicate rows from the result set and one row is kept from each group of duplicates. Let's try with DISTINCT clause:
SELECT DISTINCT a.nik, a.nama, g.ket as job, h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
What is your result?
I've got same result set with previous!
DISTINCT ON
Now try with this command:
SELECT DISTINCT ON (nik,nama) a.nik, a.nama, g.ket as job,h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
=========================================================
nik nama job akunno alokasi
=========================================================
100.200 ALBERT Manajer 400 0.00
100.300 JHONI Danru Satpam 423 1.00
100.400 ZAENAL Anggota Satpam 423 1.00
100.500 ROBI Anggota Satpam 423 1.00
200.400 TEDDY Operator St. Kempa 603.07 0.40
300.500 JOKO Operator Kolam Limbah 603.11 0.50
300.650 SEPTIAN Operator St. Kempa 603.09 0.20
400.600 OPA OPO Kerani I TUK 401 1.00
---------------------------------------------------------
Those are the result set that I want.
DISTINCT ON ( expression [, ...] ) keeps only the first row of each set of rows where the given expressions evaluate to equal. The DISTINCT ON expressions are interpreted using the same rules as for ORDER BY. Note that the "first row" of each set is unpredictable unless ORDER BY is used to ensure that the desired row appears first.
The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s). The ORDER BY clause will normally contain additional expression(s) that determine the desired precedence of rows within each DISTINCT ON group.
Firt, list the data using this statement:
SELECT a.nik, a.nama, g.ket as job, h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
=========================================================
nik nama job akunno alokasi
=========================================================
100.200 ALBERT Manajer 400 0.00
100.300 JHONI Danru Satpam 423 1.00
100.400 ZAENAL Anggota Satpam 423 1.00
100.500 ROBI Anggota Satpam 423 1.00
200.400 TEDDY Operator St. Kempa 603.07 0.40
200.400 TEDDY Operator St. Kempa 603.08 0.40
200.400 TEDDY Operator St. Kempa 603.09 0.20
300.500 JOKO Operator Kolam Limbah 603.11 0.50
300.500 JOKO Operator Kolam Limbah 603.12 0.50
300.650 SEPTIAN Operator St. Kempa 603.09 0.20
300.650 SEPTIAN Operator St. Kempa 603.07 0.40
300.650 SEPTIAN Operator St. Kempa 603.08 0.40
400.600 OPA OPO Kerani I TUK 401 1.00
----------------------------------------------------------
DISTINCT
DISTINCT will remove all duplicate rows from the result set and one row is kept from each group of duplicates. Let's try with DISTINCT clause:
SELECT DISTINCT a.nik, a.nama, g.ket as job, h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
What is your result?
I've got same result set with previous!
DISTINCT ON
Now try with this command:
SELECT DISTINCT ON (nik,nama) a.nik, a.nama, g.ket as job,h.akunno, h.alokasi
FROM ester.maskar a
INNER JOIN ester.setnamajob g ON a.jabid=g.idku
INNER JOIN ester.setnamajobakun h ON g.idku=h.jobid
WHERE a.thn=2012 AND a.unitid = 16 ORDER BY a.nik, a.nama
=========================================================
nik nama job akunno alokasi
=========================================================
100.200 ALBERT Manajer 400 0.00
100.300 JHONI Danru Satpam 423 1.00
100.400 ZAENAL Anggota Satpam 423 1.00
100.500 ROBI Anggota Satpam 423 1.00
200.400 TEDDY Operator St. Kempa 603.07 0.40
300.500 JOKO Operator Kolam Limbah 603.11 0.50
300.650 SEPTIAN Operator St. Kempa 603.09 0.20
400.600 OPA OPO Kerani I TUK 401 1.00
---------------------------------------------------------
Those are the result set that I want.
DISTINCT ON ( expression [, ...] ) keeps only the first row of each set of rows where the given expressions evaluate to equal. The DISTINCT ON expressions are interpreted using the same rules as for ORDER BY. Note that the "first row" of each set is unpredictable unless ORDER BY is used to ensure that the desired row appears first.
The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s). The ORDER BY clause will normally contain additional expression(s) that determine the desired precedence of rows within each DISTINCT ON group.
Minggu, 09 September 2012
Eclipse: Tomcat Server ports are already in use
Working with Eclipse IDE, I use Apache Tomcat to hosting applications on Windows. I forgot what I've done when encounter this problem:"Several ports required by Tomcat are already in use."
C:>TASKLIST /FI "PID eq 5740"
C:>TASKKILL /F PID 5740
then re run the server from Eclipse environment.
Yes, there must be another process using the ports. Apache Tomcat service was not started on Windows Sevices. Also I've checked using web browser http://localhost:8080/ and I got status report 404 message. Yes Apache Tomcat still run and listening on 8080. I suspect that the problem arises because using Eclipse incorrectly.
To list the listening port using: C:>NETSTAT -na | find "LISTENING"
Yes they were running. The running process could not stopped when exit from Eclipse IDE. Oh yeah, i've terminated the Eclipse IDE abnormally using End Process on Task Manager. So I have to kill the PID:
C:>TASKLIST /FI "PID eq 5740"
C:>TASKKILL /F PID 5740
then re run the server from Eclipse environment.
It works.
Langganan:
Postingan (Atom)