All Things Techie With Huge, Unstructured, Intuitive Leaps
Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Linux, List all directories in current directory And MySQL SQL script won't load

Tip1: Type ls -d */ to list directories within the current directory using Linux. (The reason why I am posting it here, is that I forgot it.

The other thing that threw me tonight, was that I had a tab or multiple spaces in an SQL script, and I just got a huge listing every time that I tried to load the script. Again, I solved this issue before by taking out the extra multiple spaces and tabs, but I had forgotten this.

Hope this helps someone.


Java MySQL SQL Tip Comparing Timestamp in Column to Current DateTime

There are many ways to skin a cat. I have a database table where I have to compare a column timestamp with the current date/time as well as adding hours and minutes. I realize that there is an SQL NOW function, but I also need the now time converted to calendar to be able to add and subtract calendar units, and I construct the SQL statement in Java.

Here is the syntax of the snippet in Java for comparison to the current datetime:

java.util.Date utilDate = new java.util.Date();
java.sql.Timestamp sqlDate = new java.sql.Timestamp(utilDate.getTime());
try {
stmt = conn.createStatement();
String myQueryString = "SELECT * FROM sale_table where saleStart < {ts '" + sqlDate.toString() + "' }";