Apache / Tomcat – PostgreSQL – Sample Database Query

 

Background

A few weeks ago I covered a little Java/JDBC-JSTL Application.  The app read data out of a Microsoft SQL Server DB.  The application sat on a Apache Tomcat which is an Opensource Web Server and Servlet Container.

Here is similar version that reads data from a PostgreSQL Database.

There are many similarities between the original Application and this one and I will forsake cut/paste tendencies and omit much here.

Additionally, in truth this was a much quicker implementation.

The URL for the MS SQL Server implementation  is https://danieladeniji.wordpress.com/2014/04/24/technical-apache-tomcat-microsoft-sql-server-sample-database-query/ .

 

PostgreSQL JDBC Driver

Download Location

As of May 17th, 2014, the latest PostgreSQL is version 9.3.  It is available @ http://jdbc.postgresql.org/download.html

 

 

Versioning

There are 3 versions of the JDBC Available.

JVM Version JDBC Version Driver Version
v 1.7, v 1.8 JDBC41 Postgresql Driver, Version 9.3-1101
v 1.6 JDBC4 Postgresql Driver, Version 9.3-1101
 v 1.5 JDBC3 Postgresql Driver, Version 9.3-1101

 

Depending on our JVM, we will download one of the above.

What is your JVM?

Version:

java -version

Output:

java --version

 

 

Download

As we JVM 1.8, we will down the JDBC41.jar

The exact URL is http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar

 

Sample:

wget "http://jdbc.postgresql.org/download/postgresql-9.3-1101.jdbc41.jar" -O "/tmp/postgresql-9.3-1101.jdbc41.jar"

 

Output:

DownloadPostgresSQL

 

Where is $CATALINA_HOME/lib

We know we need to place the jar file in $CATALINA_HOME/lib… What and Where is that?

We installed Apache Tomcat version 6 using yum, and our install location is /usr/share/tomcat6.

Underneath /usr/share/tomcat there is a lib folder; which is actually a symbolic link to /usr/share/java/tomcat6.

 

Confirm $CATALINA_HOME/lib Folder Contents

Let us see if there are other jdbc jar files in that location…

Sample:

ls /usr/share/tomcat6/lib/*jdbc*.jar

 

Output:

lib--jdbc

 

Copy JDBC Jar files into $CATALINA_HOME/lib

We need to copy postgresql-*jdbc.jar unto the lib folder.

Syntax:

sudo cp <jar-files> <tomcat>/lib

Sample:

sudo cp /tmp/postgresql-9.3-1101.jdbc41.jar /usr/share/tomcat6/lib

 

Confirm JDBC file copied

Syntax:

ls <tomcat>/lib/*jdbc*

Sample:

ls /usr/share/tomcat6/lib/post*jdbc*.jar

 

Output:

tomcat-lib-files

 

JSTL

Download Location

Download javax.servlet.jsp.jstl-1.2.1.jar from http://search.maven.org/#browse|-1002239620

Code – WAR File

File Contents

Here are the regular files that we will be including in our Jar file:

  • WEB-INF/web.xml
  • WEB-INF/lib
  • WEB-INF/classes
  • META-INF/context.xml
  • html files
  • image files
  • jsp files
  • 3rd Party Jar files – jstl files

 

Here are the files that we will not be including:

  • Notice that you do not to indicate the manifest file, as that file is auto created

 

WAR File – Folder Structure

 

Folder Folder/Sub-file What? Sample
WEB-INF Web Information
web.xml Web Configuration File
 lib Jar files 3rd party and application jar files (jstl*.jar)
 classes Compiled java files
META-INF Meta Information about the Jar file
 context.xml

 

 

Source Code Location

On our system, we will place our source files in /home/dadeniji/development/apache.org/tomcat/NBADraft

 

Create empty file structure

Create empty file structure


if [[!-e WEB-INF ]]; then
   sudo mkdir -p WEB-INF


if [[!-e WEB-INF/lib ]]; then
   sudo mkdir -p WEB-INF/lib

if [[!-e WEB-INF/classes ]]; then
   sudo mkdir -p WEB-INF/classes


if [[!-e META-INF ]]; then
   sudo mkdir -p META-INF



 

 

WEB-INF/web.xml

Create WEB-INF/web.xml

Here is the contents of our web xml file:


<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app
   version="2.5"
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xsi="http://www.w3.org/2001/XMLSchema-instance" 
   schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <resource-ref>
        <description>DB  Connection</description>
        <res-ref-name>DBSport</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    	<res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

</web-app>

 

There are a couple of areas to note:

  • Our app version is targeting Servlet/JSP API version 2.5
  • For our DB, we are defining a resource self-named DBSport and its type is javax.sql.DataSource

 

 

META-INF/context.xml

Create META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>

<Context>

 <Resource
  name="DBSport"
  auth="Container"
  type="javax.sql.DataSource"
  username="nbadraft"
  password="sleeper"
  driverClassName="org.postgresql.Driver"
  url="jdbc:postgresql://DBPostgreSQL:5432/DBSport"
  maxActive="1000"
  maxIdle="30"
  maxWait="10000"
  factory="org.apache.commons.dbcp.BasicDataSourceFactory" 
  logValidationErrors="true" 
 >
 </Resource>


</Context> 
 

There are a couple of areas to note:

  • We are further defining our database resource, DBsport
  • Its type is javax.sql.DataSource
  • The username & password that is predefined on the DB are noted
  • The Driver Class Name for MS SQL Server JDBC 4.0 is indicated as org.postgresql.Driver
  • The Url is “jdbc:postgresql://DBPostgreSQL:5432/DBSport
  • For the Connection factor we are hard-coding org.apache.commons.dbcp.BasicDataSourceFactory
  • And, logging validation errors via set setting logValidationErrors to true

 

Copy jstl jar files into WEB-INF lib

Here are the steps to copy the jstl files under WEB-INF/lib:

 


if [[ !-e WEB-INF/lib ]]; then
   sudo mkdir -p WEB-INF/lib

sudo cp --update /tmp/jstl/javax.servlet.jsp.jstl-1.2.1.jar  WEB-INF/lib

sudo cp --update /tmp/jstl/javax.servlet.jsp.jstl-api-1.2.1.jar  WEB-INF/lib

Source Code :- jspSimple.jsp

Here is a sample source code that connects to the hard coded sql server and relies on JDBC APIs to query and return the recordset from a table.

 

<html>
<head></head>
<body>
	<%@ page import="java.sql.*" %>
	<%
             String CLASSNAME_DB = "org.postgresql.Driver"; 

	     String connectionUrl = "jdbc:postgresql://DBPostgreSQL:5432/DBSport?user=dbuser&password=dbpassword";

             String strSQLStatement =
                    "select * from \"public\".\"NBADraft\"  limit 100  ";
                
       Connection con = null;
       Statement statement = null;
       ResultSet resultset = null;
 
       Class.forName(CLASSNAME_DB); 

       con = DriverManager.getConnection(connectionUrl); 

       statement = con.createStatement() ; 

       resultset = statement.executeQuery(strSQLStatement);

 %>
 
  <table> 
  <tr>
  <th><b>Athlete</b></th>
  <th><b>Year </b></th>
  <td><b>School</b> </th>
  <td><b>Position</b> </th>
  <td><b>Age</b> </th>
  <td><b>Age</b> </th>
  <td><b>Weight (lbs)</b> </th>



  </tr>

<% 
   while (resultset.next())
   { 
%>
 
<tr> 

    <td><%= resultset.getString("Athlete") %></td> 
    <td><%= resultset.getString("draftYear") %></td> 
    <td><%= resultset.getString("school") %></td>
    <td><%= resultset.getString("position") %></td>
    <td><%= resultset.getString("age") %></td>
    <td><%= resultset.getString("vitalsHeight") %></td>
    <td><%= resultset.getString("vitalsWeight") %></td>




</tr>

<% 
} 
%> 

</table>
</body> 
</html> 

 

Source Code :- explicit.jsp

The code below relies on the Context (part of javax.naming.*) and DataSource (part of javax.sql*).

Obviously, javax.naming.Context allows us to hide the server name and authentication credentials in xml files outside of the Source Code.

 

<%@   page   contentType="text/html;charset=UTF-8" %>   
<%@   page   import="java.sql.*" %> 
<%@   page   import="javax.sql.*" %> 
<%@   page   import="javax.naming.*" %> 
<HTML>
<HEAD>
<TITLE>JSP example</TITLE>
</HEAD>
<BODY>
  <h1>Hello,test JNDI !  </h1>
  <%
    Context ctx = new InitialContext();  

    Context envctx =  (Context) ctx.lookup("java:comp/env"); 
    DataSource ds =  (DataSource) envctx.lookup("DBSport");  

    //DataSource ds = (DataSource) ctx.lookup("DBSport");

    Connection  conn=ds.getConnection();   
    Statement  st=conn.createStatement();
    String    sql="select * from \"NBADraft\"    ";  
    ResultSet    rs=st.executeQuery(sql); 
    while(rs.next())   {
  %>   
       Athlete:<%=rs.getString(1) %>  
       DraftYear:<%=rs.getString(2) %> 
       School:<%=rs.getString(3) %>
       Position:<%=rs.getString(4) %>
       Age:<%=rs.getString(5) %>
       Height:<%=rs.getString(6) %>
       Weight:<%=rs.getString(7) %>
       
 
       <br>
  <%
   }
  %>

   
  <%
   rs.close(); 
   st.close();  
   conn.close();   
  %> 
</BODY>
</HTML> 

Source Code :- queryDB.jsp

The code below uses JSTL tags.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>


<sql:query var="rs"
        dataSource="DBSport"

>
   select * from "NBADraft"
</sql:query>



  <head>
    <title>DB Test</title>
  </head>

  <body>

       <h2>Results</h2>


     <table border="1" align="center" valign="center">
	<th>Athlete</th>
	<th>Year</th>
	<th>School</th>
	<th>Position</th>
        <th>Age</th>
        <th>Height</th>
        <th>Weight</th>


       <c:forEach var="rs" items="${rs.rows}">

	<tr>
	    <td><c:out value="${rs.Athlete}"/>&nbsp;</td>
	    <td><c:out value="${rs.draftYear}"/>&nbsp;</td>
	    <td><c:out value="${rs.school}"/>&nbsp;</td>
	    <td><c:out value="${rs.position}"/>&nbsp;</td>
	    <td><c:out value="${rs.age}"/>&nbsp;</td>
	    <td><c:out value="${rs.vitalsHeight}"/>&nbsp;</td>
	    <td><c:out value="${rs.vitalsWeight}"/>&nbsp;</td>
		
         </tr>

     </c:forEach>

    </table>
  

   </body>

</html>

Create Jar file

Here are the steps to create a jar file

Syntax:

jar cvf <war-file> *.jsp *.html images WEB-INF META-INF
 

 

Sample:

jar cvf NBADraft.war *.jsp *.html images WEB-INF META-INF
 

 

View Jar file Contents

View Jar file contents

Syntax:

jar tf <jar-file>
 

Sample:


jar tf NBADraft.war

Output:

jar list

 

 

Deploy – Manual

Manually deploy jar file by copying the war file into your webapps folder

There is a very noteworthy coverage of manually deploying WAR file available @

http://www.manydesigns.com/en/portofino/portofino3/3_1_x/installation-guide/deploying-on-tomcat/#TOC-Manually-deploying-and-configuring

#un-deploy war
if [[ -f "/usr/share/tomcat6/webapps/NBADraft.war" ]]; then

echo "Removing file /usr/share/tomcat6/webapps/NBADraft.war ."

  sudo rm "/usr/share/tomcat6/webapps/NBADraft.war"

   echo "Removed file /usr/share/tomcat6/webapps/NBADraft.war"

fi

#deploy war
echo "Deploying file /usr/share/tomcat6/webapps/NBADraft.war.."

 sudo cp NBADraft.war /usr/share/tomcat6/webapps/NBADraft.war

echo "Deployed file /usr/share/tomcat6/webapps/NBADraft.war"

Deploy – Verification – CATALINA_HOME/conf/Catalina/localhost/<APP-NAME>.XML

Review CATALINA_HOME/conf/Catalina/localhost and look for a configuration file (XML) bearing your Application Name.

In our case, our folder’s name is /usr/share/tomcat/conf/Catalina/localhost

conf--Catalina--localhost--folder

 

And, the file we are looking for is NBADraft.xml

File Contents:

catalina--localhost--NBADraft

 

 

Diagnostic Steps

Use lsof

Use lsof to determine where tomcat jdbc jar files are being loaded from:

Sample:

sudo lsof | grep -i "tomcat" | grep -i "jdbc"

 

Output:

grep--tomcat--jdbc

 

Run-Time Error Messages

javax.servlet.servletException : java.lang.ClassNotFoundException: org.postgresql.Driver

The exact error message is:


javax.servlet.ServletException: java.lang.ClassNotFoundException: org.postgresql.Driver
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
	org.apache.jsp.jspSimple_jsp._jspService(jspSimple_jsp.java:125)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

Diagnostic:

Check loaded jdbc jar files
sudo lsof | grep -i "jdbc"

 

Output:

lsof--jdbc

Explanation:

  • Noticed that tomcat has the Microsoft’s sqljdbc4 loaded, but our postgresQL jdbc driver is not loaded
  • Remembered that I have yet to restart tomcat since I copied the PostgreSQL file to our tomcat folder
  • Let us go restart tomcat ( sudo service tomcat6 restart ) and recheck lsof

 

Here is the output:

Output:

tomcat-restart--postgresql

Explanation:

  • Along with sqljdbc4.jar, we know have /usr/share/java/tomcat6/postgresql-9.3-101.jdbc41.jr

 

javax.servlet.servletException : org.postgresql.util.PSQLException: FATAL : no_pg_hba.conf entry for host <hostname>, user <ApplicationName>, database “<database-name;user=<username>;password=<password>”,SSL of

The exact error message is:

javax.servlet.ServletException: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "10.0.4.27", user "tomcat", database "DBSport;user=nbadraft;password=s1eeper", SSL of

 

Changed Connection URL to

Syntax:

jdbc:postgresql://hostname:portNo/DBS?user=username&password=pwd

Sample:

jdbc:postgresql://PostgreSQL:5432/DBSport?user=nbadraft&password=hello

 

Source Control

Github

https://github.com/DanielAdeniji/JavaJSPJSTLPostgreSQL

 

References

References – JSTL – Blog

References – JSTL – Tutorial

 

References – JSTL – Jar Files Repository

References – PostgreSQL

 

References – Linux – vi

 

Technical: Sun\Oracle – Installing and Configuring Java in Preparation of Hadoop Install on CentOS (v6.5)

 

 

Technical: Sun\Oracle – Installing and Configuring Java in Preparation of Hadoop Install on CentOS (v6.5)

Background

Preparing to revisit install of Apache’s Hadoop install and configuration on our CentOS machines.

I know that we need Sun/Oracle’s branded Java, but that the bundled Java is the OpenJDK version.

Let us go fix that.

 

Get Java Vendor & Version

That is, let us determine our installed Java Vendor and Version Number.

Help is going to come from:

What is the Value of Java_HOME for Cent OS
http://serverfault.com/questions/50883/what-is-the-value-of-java-home-for-centos

 

Syntax:

update-alternatives --display <app-name>

 

Command:

update-alternatives --display java | egrep "link | priority"

 

Output:

update-alternatives--display--before

 

Our output reads “link currently points to /usr/lib/jvm/jre-1.7.0-openjdk/bin/java” and so it appears that we are using OpenJDK.

We know Apache will rather have us use Sun\Oracle JDK.  And, so let us go get that.

Listing of Oracle JDK version 8 (JDK 1.8)

Using a web browser, journeyed to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and here is what we see.

Java-JRE-Selections

 

 

Download JDK v8  (JDK 1.8 – Linux x86 – RPM)

Though we can download through GUI\web browser, we have chosen to download via wget.

http://stackoverflow.com/questions/10268583/how-to-automate-download-and-installation-of-java-jdk-on-linux

 

Syntax:


wget --no-check-certificate --no-cookies  --header "Cookie: oraclelicense=accept-securebackup-cookie" <url> -O <file>

 

 

Command:


wget --no-check-certificate --no-cookies  --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.rpm" -O "/tmp/jdk-8-linux-i586.rpm"

 

 Output:

wget

Install Oracle / Sun Java JDK

Syntax:

sudo yum install -y <jdk-rpm>

Sample:

sudo yum install -y /tmp/jdk-8-linux-i586.rpm

 

Review Installed RPMS (Java)

Let us query rpm and make sure that our new JDK rpm is installed.

Syntax:

rpm -qa 

 

Sample:

rpm -qa | grep jdk

 

Output:

x64

rpm-qa-java

 

x32

rpm --qa -- grep jdk

 

Uninstall OpenJDK RPMs


Syntax:

sudo rpm -e <package>

 

Command:

x64

sudo rpm -e java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686

 

x32

To uninstall java-1.6.0-openjdk-1.6.0.0-3.1.13.1.el6_5.i686

sudo rpm -e java-1.6.0-openjdk-1.6.0.0-3.1.13.1.el6_5.i686

 

To uninstall java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.i686


sudo rpm -e rpm -e java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.i686

but, we get

Textual:


error: Failed dependencies:
libjawt.so(SUNWprivate_1.1) is needed by (installed) libreoffice-core-1:4.0.4.2-9.el6.i686

Image:

openJDKNeededByLibreOffice

 

with the strong confirmation that LibreOffice is using open JDK 1.7, we are going to have to live with it.

Installed Files – Java

List installed locations and files for Sun\Oracle Java

Table:

Folder Binary
/usr/java/jdk1.8.0/jre/bin
java
javaws
 /usr/java/jdk1.8.0/bin
jar
java
javac
javaws

 

 

 

Alternatives – Install / Updates – Console

Alternatives can be used to manage cases where an Application is bundled by one more Vendor.  Or where a couple of versions is installed by same Vendor.

Let us register our installed Sun/Oracle java as an alternative.

Syntax:


alternatives --install <link> <name> <path> <priority>

 

Command:


## java ##
alternatives --install /usr/bin/java java /usr/java/jdk1.8.0/jre/bin/java 20000

## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0/jre/bin/javaws 20000 

## Install javac only if you installed JDK (and we did)
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0/bin/javac 20000 

##install jar only if you installed JDK (and we did)
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0/bin/jar 20000 


Alternatives – Update

Command:

## java ##
sudo update-alternatives --set java /usr/java/jdk1.8.0/jre/bin/java
sudo update-alternatives --set javaws /usr/java/jdk1.8.0/jre/bin/javaws

## Install javac/jar only if you installed JDK package 
sudo update-alternatives --set javac /usr/java/jdk1.8.0/bin/javac
sudo update-alternatives --set jar /usr/java/jdk1.8.0/bin/jar

 

If you get an error message that reads:

“/usr/bin/jdk1.8.0/jre/bin/java has not been configured as an alternative for java”, then please review the earlier batch of “alternatives –install” and make sure that you have typed the correct and full path name to your binary files

HasNotBeenConfiguredAsAnAlternativeForJava

 

Update System Path File (/etc/profile)

Using your editor of choice, Add the following to the bottom of your /etc/profile:

In our case, we will use vi and invoke as “sudo vi /etc/profile

# Update System with Sun\Oracle Java Information
# set JAVE_HOME to Sun\Oracle Install Location
JAVA_HOME=/usr/java/jdk1.8.0

# set JRE_HOME to Sun\Oracle Install location
JRE_HOME=/usr/java/jdk1.8.0

# add User $HOME/bin and aforementioned $JAVA_HOME/bin to path
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

 

 

Effect System Path File (/etc/profile) Changes

Since we do not want to force a restart before we proceed, let us force execution of our /etc/profile.

sudo sh /etc/profile

 

Review Alternatives – Java

Update-alternatives –display

Syntax:

update-alternatives --display <app-name>

 

Command:

update-alternatives --display java | egrep "link | priority"

 

Output:

UpdateAlternatives -- display java

Explanation:

  • We see that our current alternatives pointer is directed @ /usr/java/jdk1.8.0/jre/bin/java

 

Update-alternatives –config

 

Syntax:

update-alternatives --config java

 

Output:

alternatives --config

 

Explanation:

  • Selection 2 is tagged with an *, as “Open JDK 1.7” has the highest priority ( 170051 )
  • Selection 3 is tagged with a +, as the Sun/Oracle’s  JRE Java is our current selection

Review Install Java Version

Java Version?

Command:

java -version

 

Output:

java_version_question

 

Javac Version?

Command:

javac -version

 

Output:

javac_version_question

References

References – Java on CentOS

 

References – Java on Debian

 

References – Java on Ubuntu

 

References – Alternatives – Java

 

Technical: Mac OSX / Java Applet Support in Mozilla Firefox

Technical: Mac OSX / Java Applet Support in Mozilla Firefox

Here I am trying to upload files to one of our vendors, but the upload icon is not appearing in Mozilla Firefox.

I looked all over, but no plugin.

I am thinking you ‘re killing me.  And, yes where did I look?

Well in Add-On Manager; specifically the Plugins Tab.

How to get there:

  • Menu Bar – Tools \ Add-ons..
  • Tab – Plugins

Goggled for help and confirmed that I am doing what I should be doing:

How do I disable Java in my web browser?
http://java.com/en/download/help/disable_browser.xml

Firefox
  1. Click on the Firefox tab and then select Add-ons
  2. In the Add-ons Manager window, select Plugins
  3. Click Java (TM) Platform plugin to select it
  4. Click Disable (if the button displays Enable then Java is already disabled)

But, I am thinking no Java Plugin.

Finally got some help:

Use the Java plugin to view interactive content on websites
http://support.mozilla.org/en-US/kb/use-java-plugin-to-view-interactive-content#os=mac&browser=fx21

Installing or updating Java

And, here are the steps I took:

  • Used Browser to access http://support.apple.com/downloads/#java
  • Downloaded Apple’s version of Java (javaForOSX2013-002.dmg).  
  • On Mac,  Accessed System Preferences \ Java \ Java Control panel
  • In “Java Control Panel” \ “Security” Tab – Ensured that “Enabled Java Control content in Browser” is checked
  • Restarted Browser, but alas still no Java.

BTW, that website (http://support.apple.com/downloads/#java) is not always accessible.

So what to do, but tightened up my Google Search.

I am thinking I need some music.  There is an old school rap track that says something about “… Just your luck, Greyhound is on strike”.  Tried it, but it is a bit of a downer.  DJ Quik -Tonite is also shown on same YouTube page.  And, I knew that will help.

DJ Quik – Tonite
http://www.youtube.com/watch?NR=1&v=hykZtBaPKps&feature=endscreen

Went back and Googled some more.  And, found:

MozillaLine – Java
http://kb.mozillazine.org/Java#On_Mac_OS_X

Found out a couple of things:

  • Mozilla is actively adding plugins to its BlockList

JavaAndFlashPlugins

So it appears that Mozilla is heeding to all this stuff coming from the “State Department” and actively blocking even recent Java Plugins.

The MozillaLine article led me to:

Information and system requirements for installing and using Mac Java 7
http://www.java.com/en/download/faq/java_mac.xml

So I am thinking I need the very latest java and that is available from:

Upon downloading Oracle’s java version and installing it, I am now able to use Java Applet’s (inside of Firefox).

Confirmation Steps

Apple – OSX – System Preferences – Other\Java – Java Control Panel

One can have a few different versions of Java JRE installed – You can have Oracle\Sun’s, Apples, etc.

Please make sure that the one enabled is Oracle\Sun’s 1.7._0_17

  • On OSX, access “System Preferences”
  • Access the Other sub-group, Java applet
  • Access “Java Control Panel”
  • Access the Java Tab
  • Click the “View…” button
  • Ensure that Oracle’s JRE is the only enabled option

Mozilla – Add-ons Manager

Ensure that “”Java Applet Plug-in Java 7 Update 17” is enabled.

  • Launch Mozilla
  • Menu Bar – Tools \ Add-ons..
  • Tab – Plugins

In the list of Plugins, you will see “Java Applet Plug-in Java 7 Update 17”

Conclusion

With BlockList and the like, it appears that Browsers are joining OS and Virus Security vendors in actively armoring their users.

For you, the user, and corporate help-desk, keep that in mind when you get support calls.

In terms of security and how it is effected, things appear to be changing all the time.

In an earlier post (https://danieladeniji.wordpress.com/2013/02/02/mac-osx-sunoracle-java-applet-typical-workspace-interaction/) on this subject, I concluded that I could not really get Java Applets to work inside Apple’s Safari Browser.  That is no longer the case, it works with the new Oracle\Sun JRE.

It might be that Apple has relaxed its security constraints on the above configuration.

References

Mac OS/X – Sun/Oracle – Java Applet – Typical workspace interaction

Mac OS/X – Sun/Oracle – Java Applet – Typical workspace interaction

Google Chrome

Java Applet (needs permission to run) Chrome - Java Applet (needs permission to run)

So we are asked to confirm whether we want Java to run:

  • Always run on this site
  • Run this time

We chose to have it “Run this time”.

Chrome - Java Applet (Need to download the java plug-in)

We did not get very far.  We are greeted with a warning message stating “Missing Plug-in” and prompted to download Java plug-in.

There is no need to go much further.  Java is delivered as a 64-bit plugin on 64-bit Mac OS-X.  And, Google Chrome is 32-bit.

Safari

Safari - Java Applet

Safari is stucked at the “Missing Plug-in” spot.

And, even post install of Java Plug-in, Safari is not allowing the applet to run.

Firefox

Firefox - File Browse (pre plug-in acceptance)

So in Firefox, the browser asks whether it is OK to execute the “FileBrowse” plugin from Netapp; specifically upload.netapp.com

We reply yes and we are good.

Firefox - File Browse (post plugin acceptance)

We are able to click on the “Browse File” button and launch an Applet which exposes the “File Open” dialog on our screen.

So on a Mac with Java JRE installed, here is a round-up of Java JRE/Applet support:

  • Google Chrome – Stuck due to Sun/Oracle JRE being provided as a 64-bit utility and Chrome being to 32-bit
  • Apple Safari – Stuck
  • Firefox – Good

To review and get more granular insight into your Mac OS Support:

  • Launch “System Preferences”
  • In the other section, select “Java”

System Preferences

In the Java section, there are many options:

Java Control Panel - General

In the General section:

  • Access the “Network Settings” — Which allows one to choose a different proxy setting, than the one set for the browser

Java Control Panel - General - Network Settings

In the “Update” section:

Java Control Panel - Update

  • Choose whether you want Java updates to occur automatically
  • In our case, one can see we have a relative recent update.  Due to the recent proliferations of exploits you probably want it so

In the “Java” section:

Java Control Panel - JRE - Versioning (Select Version)

  • This is especially when you have two or more JREs installed, and you want to select the one you want
  • Obviously, you can also Disable all of them
  • Advanced users can also specify “Runtime parameters”

In the “Security” section:

Java Control Panel - Java Applet - Security Level

  • This is quite important as you are able to disable Java for all web browsers
  •  And, if you choose to enable it, be a bit more granular and set security level
  • Also, for security conscious configurations, choose which certificates you want exposed

In the “Advanced” section:

Java Control Panel - Advanced

So here I am thinking since the OS exposes the functionality to disable Java Plugin\applets, I am good if I choose to use the OS Functionality to do so.

I disabled it:

  • Access “System Preferences”
  • In the “System Preferences” window, “Other” section : Choose the “Java” icon
  • In “Java Control Panel” \ “Security” Tab, disable “Java” in the browsers

Java Control Panel - Security ( java disabled in browser)

So here I go return to Firefox and try to use the NetApp applet and it still works.

So I am thinking let me restart my browser and here again, I am still working.

So I am thinking those NetApp Developers are very smart and that they dutifully and gracefully degraded to HTML; as it allows file upload, as well.

But, before packing up my little project, I am thinking I should view the web Application’s source.

Wish I could say I found the “View Source” button easily, but that I had to Google for it.

How to view Source

http://support.mozilla.org/en-US/questions/862421

Tools Menu -> Web Developer -> click View Page Source

It seems that the Applet is still being used and ran.  The code for Applet is present and there is no conditional statement around it:



<APPLET  
	CODE = "org.sslupload.FileBrowseApplet.class" 
	archive="/hq/Userfile?send=applet&name=SSLUpload.jar" 
	WIDTH = 100% 
	HEIGHT = 40 
	NAME = "FileBrowse" 
	MAYSCRIPT = true>

</APPLET>

So it seems that the Java Applet is still being ran.

So Googled again. How to disable Java in Firefox:

http://support.mozilla.org/en-US/kb/How%20to%20turn%20off%20Java%20applets
How to turn off Java applets

This article explains how to disable the Java plugin in Firefox so that Java applets no longer run.

By default, Firefox allows Java applets to launch automatically. However, you may decide that you do not want Java applets to run. To disable Java applets in Firefox:

On the menu bar, click on the Tools menu, and then click Add-ons. The Add-ons Manager tab will open.
In the Add-ons Manager tab, select the Plugins panel.
Click on the Java Plug-in 2 for NPAPI Browsers (Mac OS 10.6) or Java Applet Plug-in (Mac OS 10.7 and above) to select it.
Click on the Disable button (if the button says Enable, Java is already disabled).
Java applets will no longer be permitted to launch in Firefox.

Firefox - Plugins - Java Applet Plug-in

Once we clicked on the disable button on the “Java Applet Plug-in” entry, we are good:

Firefox - Plugins - Java Applet Plug-in (disabled)

the applet icon is now “X-ed” out.

So moral of the story.

  • Certain functionalities might be disabled at the OS level, but sometimes 3rd parties in this case Mozilla built a way around it.  In Firefox, they are controlling their own destiny by exposing Java JRE toolset as a plug-in

 

References:

 

 

 

Java – JStack

Java – JStack

When reviewing \ debugging a Java Application, one can try using “JStack”.

JStack principally displays the StackTrace for each thread in an Application.

Listed below are a few well written coverage of this important tool.
1) Fun with JStack
http://weblogs.java.net/blog/sdo/archive/2009/10/16/fun-jstack
2) How to take Thread Dumps from a JVM
http://dev.day.com/content/kb/home/cq5/CQ5SystemAdministration/TakeThreadDump.html
3) JStack / Oracle
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html
4) Building a JStack Profiler
http://codingbone.wordpress.com/2010/05/25/building-a-jstack-parser/
5) What are good Java Profiling Tools
http://qnatech.wordpress.com/2009/09/17/what-are-good-java-profiling-tools/

Couple of areas to keep in mind:

  1. On a Windows box running a 64-bit OS, you will not be able to “connect” to a 32-bit App running under WOW64.

    If you try to, you will get an error message similar to “Unable to attach to 32-bit process running under WOW64” 

Oracle \ Sun Java’s Interaction with MS SQL Server – Quick Prototype – Test out Connectivity along with Stored Procedure Invocation

Needed to review Oracle\Sun Java’s Interaction with MS SQL Server:

And so did the following:

  1. Downloaded Microsoft JDBC Driver. JDBC Version 3 is the latest out
    there and so downloaded that version.
  2. TextWrangler – Text Editor
  3. Created SQL Account on the DB Server. Granted minimum required access – SQL login Access – Specific Database Access – Permission to run Stored Procedure
  4. Settled on an “un-well” known TCP Port to facilitate SQL Server Remote Access.
    Opened Firewall Rules to support it.

Now that the Environment is a bit setup, took the Easy Street and combed the .Net
for HelloDB code.

But, kept getting the error pasted below:

———————————————————————————

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at DBConnect.getConnection(DBConnect.java:70)
at DBConnect.getConn(DBConnect.java:46)
at helloDB.main(helloDB.java:21)
Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver

——————————————————————————-

Threw everything at the Problem:

  • Copied Microsoft’s JDBC Driver (sqljdbc4.jar) locally
  • Tweaked the CLASSPATH environment variable. As the Client is a Unix box
  • Learned to play “nice” with BASH
    • Used Export and unset to set & reset variable
  • Tried passing in the jar files via the -cp argument list
    • java -cp ./ helloDB
    • …. Note -cp ./ means that Java should check the local directory for Jar files
  • Copied the files to OS’s native location for JDBC Jar files

Finally gave up with trying to use Microsoft JDBC Driver. Downloaded JTDS changed a couple of lines:

1) Changed the name of the “Driver” class

from:

Microsoft’s MS SQL Server Driver:


Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

to:
jDTS Driver:

Class.forName("net.sourceforge.jtds.jdbc.Driver");

2) Changed JDBC base URL

from:
Microsoft’s MS SQL Server JDBC Driver:
jdbc:microsoft:sqlserver://

to:
jDTS Driver:
jdbc:jtds:sqlserver://

jDTS worked well, and without much changes either.

And, so now it is getting late and I am getting tired.

Did what I did not want to do, copied the files to a MS Windows box.

Really no additional setup needed as the Database Connectivity Software
are self-contained in the Jar files.

Reviewed the CLASSPATH and Invoked the App. The error message read:

 

——————————————————————————

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver

at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DBConnect_v2000.getConnection(DBConnect_v2000.java:70)
at DBConnect_v2000.getConn(DBConnect_v2000.java:46)
at helloDB.main(helloDB.java:23)
Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver

——————————————————————————

Goggled for that error message:

and found http://blogs.msdn.com/b/jdbcteam/archive/2007/06/15/java-lang-classnotfoundexception-com-microsoft-jdbc-sqlserver-sqlserverdriver.aspx

MS Doc clearly states that:

The class name has changed between the SQL Server 2000 JDBC driver and the SQL Server 2005 JDBC driver.  This particular class “com.microsoft.jdbc.sqlserver.SQLServerDriver” is the class name for the SQL Server 2000 JDBC driver.  The SQL Server 2005 JDBC driver class name is “com.microsoft.sqlserver.jdbc.SQLServerDriver“.
Note the change: from “microsoft.jdbc.sqlserver” to “microsoft.sqlserver.jdbc”

In addition, the SQL Server 2005 JDBC driver has a different URL prefix from the SQL Server 2000 JDBC driver.  The SQL Server 2000 JDBC driver uses an URL prefix of “jdbc:microsoft:sqlserver://”, while the SQL Server 2005 JDBC driver uses an URL prefix of “jdbc:sqlserver://“.
Note the removal of “microsoft” from the URL prefix.


—————————————————————————————————

So now we know what works:

Changed the name of the “Driver” class

from:

Microsoft’s MS SQL Server Driver (v2000):

Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver“);

to:

Microsoft’s MS SQL Server Driver (v2005):

Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver“);

(
please be extra careful with this one as the Class name looks the same – but the fact is that a couple of entries are inter-changed –  jdbc.sqlserver is now sqlserver.jdbc
)

2) Changed JDBC base URL

from:

Microsoft’s MS SQL Server JDBC Driver (v2000):

jdbc:microsoft:sqlserver://

to:

Microsoft’s MS SQL Server JDBC Driver (v2005):

jdbc:sqlserver://

         (
             please be a bit careful with this one as the the middle entry
             for microsoft is dropped
        )

————————————————————————

References:
1) Using the JDBC Driver
http://msdn.microsoft.com/en-us/library/ms378526.aspx
2) How to Install Microsoft SQL Server JDBC
http://www.frank4dd.com/howto/database/howto-install-Microsoft-jdbc.htm
References (jDTS)

1) The jTDS Project
http://jtds.sourceforge.net/faq.html#urlFormat
References (Setting the Classpath)

1) Setting the Classpath in Java
http://introcs.cs.princeton.edu/java/15inout/classpath.html
References (WebObjects)

1) WebObjects 5 : How to use Oracle JDBC Drivers
http://support.apple.com/kb/TA26798?viewlocale=en_US

2) How do I install JDBC Driver on 10.5
https://discussions.apple.com/thread/1487101?start=0&tstart=0

References (MalcolmHardie Solutions)

1) Microsoft SQL Server and SQLEditor
http://www.malcolmhardie.com/support/sqleditor/mssqlserver.html

References (Java for OS X Lion)

1) Java for OS X Lion Update 1
http://support.apple.com/kb/DL1421
2) Java and the Mac OS
http://introcs.cs.princeton.edu/java/15inout/mac-cmd.html
References (Java for OS X Lion – Issues )

1) Java for OS X Lion Update 1
http://support.apple.com/kb/DL1421

References (Adobe)

1) Install the Java runtime (JRE) | Mac OS 10.7 Lion
http://kb2.adobe.com/cps/909/cpsid_90908.html

References (sqljdbc.jar)

1) How to get Started with Microsoft JDBC
http://support.microsoft.com/kb/313100
2) Working with a Connection
http://msdn.microsoft.com/en-us/library/ms378956(v=sql.90).aspx

1) Running standalone Groovy Scripts
http://www.vasanth.in/

Sun/Oracle – Java – JDBC Driver – Microsoft / JDBC Driver v3.0

Playing a bit with Java JDBC Drivers this morning.

I needed a quick avenue to play with Java\JDBC Connection URL this morning.

As I did not have a simple, free JDBC-able Query tool on the machine I was using,I downloaded JaySQL from http://synametrics.com/SynametricsWebApp/WinSQLForJdbc.jsp.

The GUI is a bit difficult to use, but nevertheless configured it to point to my recently downloaded Microsoft’s JDBC Driver – http://msdn.microsoft.com/en-us/sqlserver/aa937724.  It is version 3.0 software and it works well.

Nevertheless, within JSQL I configured the JDBC Connection String and pointed to the DB Server.

But, the tool was just not working it was stuck and not quite working.

So next I tried my more trusted Cross-Platform Database Query Tool, DBVisualizer (http://www.dbvis.com/).

I set up the Driver Manager – pointed at the same JDBC Driver.

And, thankfully, it gave me a much better, cleaner, and revealing error message:

The error message states clearly – Java RunTime Environment (JRE) version 1.6 is not supported by the driver.  Use the sqljdbc4.jar class library…

Thus, configured the Driver Manager to use sqljdbc4.jar

 

 

Things worked better.

Now re-intimated with DBViz, I probably should continue using it.

But, to close off, returned to JaySQL…

a] Terminated the existing hung process

b] Re-initiated a new JaySQL process

c] Re-configured the Driver Manager to point to sqljdbc4.jar

And, now things worked better

References:

  1. Microsoft & jTDS JDBC driver broken after update to 1.6.0_29
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7105007

  2. System Requirements for JDBC
    http://msdn.microsoft.com/en-us/library/ms378422.aspx