How Do You Troubleshoot “postgresql.Driver Connection error: org.postgresql.util.PSQLException Fatal: Ident authentication failed for user”?

Problem scenario
You are trying to connect to a PostgreSQL database.  Your database username and password are not working, but you think they should.  You get the message:  "postgresql.Driver Connection error: org.postgresql.util.PSQLException Fatal: Ident authentication failed for user"

What should you do?

Possible solution #1
Make sure the pg_hba.conf file is configured correctly.

Here is an example if you are trying to connect from your local machine and you do not need your Postgres instance extremely hardened:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Possible solution #2
If you want to be very proactive, try dropping the database and dropping the role.  Then recreate both.  This way you ensure you have the correct username (aka role) and password. 

To get to a SQL prompt, you may want to try to run these two commands:
sudo su postgres
pgsql

Then run these four SQL statements:
drop database foobar;
drop user jdoe;
create user jdoe with password 'goodpassword';
create database foobar with OWNER=jdoe;

How Do You Troubleshoot “Failed to start sonar.service: Unit not found” Error?

Problem scenario
You run "sudo systemctl start sonar", but you get this message: "Failed to start sonar.service: Unit not found"

What should you do?

Solution
Run this: sudo systemctl enable sonar

Now you should be able to run your command to start the "sonar" service.

How Do You Troubleshoot the GitLab Integration Webhook Error “No valid crumb was included in the request”?

Problem scenario
You are trying to configure GitLab to work with Jenkins (so the two are integrated to enable CI, continual integration, in your environment).  When you test a connection of an integration webhook from GitLab to reach out to Jenkins you receive this error:

"Hook executed successfully but returned HTTP 403... No valid crumb was included in the request."

What should you do?

Solution
Possible solution #1
Warning: This is not a recommended practice.  This solution will make your Jenkins system less secure.  

Log into Jenkins and go to Manage Jenkins -> Configure Global Security -> CSRF Protection.  Uncheck the option for "Prevent Cross Site Request Forgery exploits".  Click "Save".

Possible solution #2
Use the "Build Authorization Token Root Plugin" for Jenkins.  If you need directions for installing it and configuring it, see this posting (How do you troubleshoot the GitLab integration webhook error "Permission...)

How Do You Troubleshoot “command not found” in a Bash Script?

Problem scenario
You have a function defined in your Bash script.   You call the function you created.  But you get "command not found".  What should you do?

Solution
The Bash script is parsed from the top of the file to the bottom of the file.  You cannot invoke the function before it has been defined.  Place the function above the line where it is called.  The function should probably go near the top despite the lack of readability.

How Do You Troubleshoot the Oracle and Java Message “java.sql.sqlexception ora-01003 no statement parsed”?

Problem scenario
You run a Java program that runs a SQL statement in an Oracle database.  You get this error: "java.sql.sqlexception ora-01003 no statement parsed".  What do you do to fix this?

Solution
Run the Java program a second time.  Does the problem remain?  It could be that there was a successful DDL command, and this error could be ignorable.  

You may want to try these links for further info:
https://stackoverflow.com/questions/23866710/ora-01003-no-statement-parsed
https://community.oracle.com/thread/736289 (this link used to work)

How Do You Use Encapsulation in Python?

Problem scenario
You know about encapsulation.  You know about private methods that are only accessible from inside a class -- not outside.  You want to encapsulate a method in a class in Python.  How do you write such a program?

Solution
"Programmers are most effective if shielded from, not exposed to, the innards of modules not their own." (This was taken from page 272 of The Mythical Man-Month.)

Here is an example; you can call the file encapsulate.py.  If you uncomment the "good_widget.__makeone()", you will see the program fail; you will see the private method __makeone() work in this program if you run it exactly how it appears below (using Python 3):

#!/usr/bin/env python

class WidgetFactory:

  def __init__(self):
    self.__makeone()

  def funtest(self):  # This is a public method.
    print('This widget is working!')

  def __makeone(self):   # This __ syntax tells Python it is a private method.
    print('creating one widget; please wait...')

good_widget = WidgetFactory()
good_widget.funtest()
#good_widget.__makeone()  #  If you uncomment this line, this line will cause the program to throw an error.

For further information:
"Python doesn't have real private methods, so one underline in the beginning of a method or attribute means you shouldn't access this method, because it's not part of the API." (This quote was taken from an external website.) "Other programming languages have protected class methods too, but Python does not." (This quote was taken from https://pythonspot.com/encapsulation/.)

How Do You Troubleshoot JIRA Not Working due to Not Finding a Suitable Driver?

Problem scenario
Atlassian JIRA is not working.  The web UI does not have a login page.  On the back-end in the logs, you see an error about not finding a suitable driver.  (You may get an error about a port number instead.  This problem may require a similar solution to the one proposed below for an error about a suitable driver.)  You know you have the ojdbc.jar file (or variation thereof) in the correct place.  What should you do?

Solution
Verify the dbconfig.xml file is configured properly.  The individual stanzas should each be verified for accuracy.  If the database hostname was entered incorrectly (and this will not necessarily be obvious), the error you get could misleadingly refer to a database driver.  The real problem could be a typo in the hostname for the database.  An incorrect database server or network disconnect between the JIRA server and the database server could be the real problem.  

If the ojdbc.jar file became corrupt, the error may not have been misleading after all.  You may actually need a new .jar file from Oracle's website.  For more information, you may want to see this link.

With awk, What Do You Do to Get a Colon To Be Recognized as a Separator of Fields?

Problem scenario
You have Awk 4.1.3 installed.  The default field separator in awk is a space.  You want to assign it to a different character -- specifically a colon ":".  You have a string with a colon assigned to the variable "y".  You have tried these things:

echo $y | awk -F ":" '/1/ {print $NF}'  # this prints nothing
echo $y | awk '{FS=":"; print $1}'  # this prints y
echo $y | awk 'BEGIN { FS=":" } /1/ { print $2}' # this prints nothing

The above commands do not recognize the ":" as the field separator.  You think regular letters would have worked as a string, but you find the colon ":" to behave differently.  What do you do to get a colon to be recognized as a separator of fields?

Solution
In some ways, this question for those Awk experts reading, is what is the functional difference between awk's "--field-separator" contrasted with Awk's "FS" reserved flag?

To find the version of awk use this command: awk -W version.  Be sure you have a new version (e.g., around 4.1.3).  To upgrade on a Debian/Ubuntu server, run this:  sudo apt-get -y upgrade gawk

For reasons we do not understand, use the unabbreviated "--field-separator" to assign the non-default character to.  The behavior is different.  We find the [more verbose] "--field-separator" works more reliably and predictably.  Here is an example:

echo $y | awk --field-separator=":" '{print $1}'

(We know the awk command is technically a programming language that was an antecedent to Perl.  Today awk is thought of chiefly as a Bash command or utility.)

How Do You Write a Java Program to Accept a Number for the Command Terminal and Print It Back Out?

Problem scenario
You want to write a basic Java program to test it out.  How do you write a program to accept user input, specifically a number, and print it back to the screen (using the integer data type)?

Solution
1.  Install the Java Development Kit if you have not installed it yet.  If you are not sure you have it, run javac -version.  If it says that the command is not found, you need to install the Java Development Kit.  If you do not know how, see this posting.

2.  Create this file named acceptNum.java:

import java.util.Scanner;

public class acceptNum {

public static void main(String[] args) {
   System.out.println("Please enter an integer, then press enter: ");
   Scanner in = new Scanner(System.in);
   int num = in.nextInt();
   System.out.println(num);
  }
 }

3.  Run this command: javac acceptNum.java

4.  Run this command: java acceptNum

If you want to purchase a book on Java, click here

How Do You Use an USB-Connected Local Camera with Your Desktop Computer?

Problem Scenario
You purchased a camera that connects to your computer (e.g., a laptop) with a USB cable.  An example may be an SQ9* camera. You now want to use it.  The device connects to your laptop via a USB mini to USB A connector.  How do you view images on your desktop that are captured with the camera lense?

Solution
(This problem assumes that the camera is not plug-and-play.  In our experience, the SQ9* is not plug-and-play.) We have a solution for Windows as well as Linux users.

Solution for Microsoft Windows Users
1.  Go to Control Panel -> Hardware and Sound -> Devices and Printers.  In "Devices" you should see a camera icon. It may say "GENERAL - UVc".  If you do not see it press the "On/Off" button on the camera.  (An SD card is not necessary for basic functionality.)

2.  Install this on your Windows desktop.

3.  Open this application (e.g., WebcamViewerV1.0.exe).  Use the drop down box to find your new camera.  Then click "Connect".

Solution for Raspberry Pi (or Debian/Ubuntu Linux) Users
1.  Open a command terminal.

2.  Enter these commands:

sudo apt-get -y update
sudo apt-get -y install vlc browser-plugin-vlc

3.  Run this command from the terminal to open the GUI application: vlc

4.  In the VLC media player application, go to Media -> Open Capture Device.

5.  In the Open Media sub-window, choose the option (usually the only option) for Video device name that corresponds to your camera.  choose the option (usually the only option) for Audio device name that corresponds to your camera.  

6.  Click "Play".

* Please note that we do not warrant that the night vision aspect of this camera will necessarily work.