All Things Techie With Huge, Unstructured, Intuitive Leaps

Facebook Privacy Slip-up - Randi Zuckerberg Family Photo

Now isn't this rich with irony.  Randi Zuckerberg posts a private family photo to Facebook and the privacy policy doesn't protect it.  They were poking each other with the new Facebook Picture Poke.  The picture goes public and Randi is not pleased.  Randi is the former marketing chief of Facebook and should know better.

Inquiring minds want to know though -- where is the lovely Mrs. Mark Zuckerberg in this photo?  Maybe she and Mark are not into poking any more?  Just saying ..

Looking to develop an Interest Engine

I exchanged emails with the founder of a startup, and we touched on the topic of linking internet content to personal interests.  This is one of the last frontiers of searches and delivering content.  A hell of a lot of money could be made if someone made a content delivery system from the web that was say, 80-90 percent right all of the time.  I suppose that the Semantic Web with it Resource Description Framework and Web Ontology Language might help, but that is a bit of pie in the sky, because there are millions if not billions of html pages already out there that will never be reworked.

So the work will have to come from the server side.  The search engines will have to get a hell of a lot better at context recognition.  However, my specific concern is matching your interests to web content. For example, suppose you listed your interest as cats.  There is the cat breeder who is interested in breeds of cats.  There is the charity who rescues cats.  Veterinarians need information on cat diseases and pharmacology.  Just putting in the word cats will create a lot of junk to sift through for each specific case.  This example is trivial because you could add another search term like "rescue" or "veterinary" etc.  But what if my interest is "neat stuff".  How would I create a machine language to search and deliver neat stuff content.

My research continues, but if you have any ideas, leave a comment.  Thanks.

Strange MySQL Error

Had a strange MySQL error:

ERROR 1033 (HY000): Incorrect information in file (table_name)

We couldn't log into our app.  It looked like the database connection wasn't happening.  The logs were useless.  All they said was that there was a null pointer exception for getting the data back from the database.

We have a Linux server, so I typed in the /etc/init.d/mysqld stop  and then issued the start command:

/etc/init.d/mysqld start .  It failed.  I did it again (stop and start) and it said OK.  I could log into the database.  I could show tables.  But when I went to select from the tables, I got the above error.

Nothing worked.  Finally I rebooted the server and it was fixed.  If anyone has an idea of what caused this, please leave a comment.

Data source rejected establishment of connection

It was frustrating. I set up a Java JDBC connection pool to MySQL, and the app ran for awhile, then it would not connect. Obviously I had leaking connections somewhere.

The message in the transcript log was:
Data source rejected establishment of connection, message from server: "Too many connections"

  I went and tried closing all of the connections, but the app is a fairly large one. What to do? I Googled around and there was no obvious way of seeing where the connection leak was, so I opted for brute force. The pseudo code for establishing a connection with at connection pool looks like this:

 DataSource ds=getDataSource();
 Connection conn=ds.getConnection();

and to close the connection, it was:


 So the way that I solved it and found the connection leak, was that I added a couple of lines to the above code.

In the open connection method, I added

System.out.println("Open Connection " + conn.toString();

and in the close method, before the close statement, I added:

System.out.println("Close Connection " + conn.toString();

It prints out stuff in the console like this:

Open  Connection ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@e78c1b]]
Close Connection ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@e78c1b]]

I then match up the open and closes as I do stuff, and find my unclosed connections leaks.

Hope this helps.

Javascript -- Round Number to nearest 100 -- Validate

I have this web page that is created by a jsp.  The user has to input an amount of money to make a bid, but I don't want the users entering silly amounts like $1098.66.  I want the amount to be in exact increments of $100.  So I have an input tag "<input tabindex='1' type='text' name='amt' id='amt' value='00.00'  size='10' />" and I want to validate and make sure that the number is an increment of $100.  When the user presses the submit button, I call onclick="javascript:validateAndSubmit()".

My validate and submit function is something like this:

var bestPrice = document.(insert Form Name).amt.value;
                //get rid of the dollar sign
var match= bestPrice.match(/[0-9,.]*/);
if (match!==null) {
                    //Make the number into a float
   var amount= parseFloat( match[0].replace(/,/g, '') ); 
                 //find out if the number is not in multiples of 100 using modulus
   var rem = amount % 100;
   if ( rem > 0)
    alert("Your offer must be in multiples of $100.")

Hope that this helps.

The Fastest And Slowest Emails among the big free providers

I use all of the big free email account providers like Gmail, Yahoo, GXM,, hotmail, etc etc.  Regular readers know that I am a data privacy freak, so every time that I have to open an account and need an email address, I do not give out my gmail because it has my real name.  I have a whole stable of free accounts.  AND, when I am asked to give another account for password recovery (or mobile phone number for that matter), I never do.

So I conducted some latency tests to see who has the fastest and slowest email.  I sent all of the tests from a linux server using the sendmail facility.  The winner by far was Gmail.  The sent messages arrived the fastest by gmail.  The loser and slowest email account was Yahoo.  I am not surprised.

The only discordant note about the speed of gmail, is that I bet Google reads my email   The ads on my gmail folder prove it.

Setting Up JNDI JDBC MySQL Connection Pool in Tomcat

So it was time to set up a connection pool for our high concurrency application.  It seemed like an easy thing to do.  I went to followed one of their instruction tutorials, and burned a whole afternoon debugging.  Tomcat 7 has connection pooling built in, so I figured it would be a walk in the park.  Man, I got the following list of errors:

  • org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.jdbc.pool.DataSource
  • name is not bound in this context. unable to find 
  • java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool DataSourceFactor
  • java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.jdbc.pool.DataSource
  • java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool DataSourceFactory
After wasting a whole bunch of time, I finally got it to bind to the database resource, but I had an error with the login stored procedure.  It was this one:

  • mysql - java.sql.SQLException: Parameter number 3 is not an OUT parameter

I knew that I was getting some sort of binding but not a good connection.  Not knowing what I didn't know, I decided to do a debug on my connection called conn:


It was quite an interesting transcript.  It told me that getMaxConnections() was zero, that allTablesAreSelectable was false, and allProceduresAreCallable() was false.  I spent a lot of time chasing down this dead end rabbit hole.

Finally I went to the expert:

I followed the instructions implicitly and voila -- every thing works:

Simple Connection Pool for MySQL

<Resource type="javax.sql.DataSource"
The first thing we notice is the factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" attribute.
When Tomcat reads the type="javax.sql.DataSource" it will automatically configure its repackaged DBCP, unless you specify a different factory. The factory object is what creates and configures the connection pool itself.
There are two ways to configure Resource elements in Apache Tomcat.
Configure a global connection pool
File: conf/server.xml
  <Resource type="javax.sql.DataSource"
You then create a ResourceLink element to make the pool available to the web applications. If you want the pool available to all applications under the same name, the easiest way is to edit the File: conf/context.xml
  <ResourceLink type="javax.sql.DataSource"
Note, that if you don't want a global pool, move the Resource element from server.xml into your context.xml file for the web application.
And to retrieve a connection from this configuration, the simple Java code looks like
Context initContext = new
   Context envContext  = (Context)initContext.lookup("java:/comp/env");
   DataSource datasource = (DataSource)envContext.lookup("jdbc/LocalTestDB");
   Connection con = datasource.getConnection();

Mister TomcatExpert is really an expert.

MySQL Connection Pooling with Java & Tomcat Tip

It is time we got serious with a webapp of my to quit setting up and tearing down connections to the mysql database.  I decided to implement a connection pool.  There are examples all over the web on how to do this.  Luckily, I am using Apache Tomcat 7 and it has the connection pooling built in.

So I was implementing the java code:

 import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;

  import org.apache.tomcat.jdbc.pool.DataSource;
  import org.apache.tomcat.jdbc.pool.PoolProperties;

and the import was throwing the class not found error.  I thought "WTH -- I am using Apache 7".  As it turns out, I had to go to the properties, and add the Apache Tomcat Library (not the jars but the libraries) in the Project Build Path.  Problem solved.  Hope this helps someone.