How to convert java.util.Date to java.sql.Date?

Nevermind…. public class MainClass { public static void main(String[] args) { java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); System.out.println(“utilDate:” + utilDate); System.out.println(“sqlDate:” + sqlDate); } } explains it. The link is http://www.java2s.com/Tutorial/Java/0040__Data-Type/ConvertfromajavautilDateObjecttoajavasqlDateObject.htm

How to declare a variable in MySQL?

There are mainly three types of variables in MySQL: User-defined variables (prefixed with @): You can access any user-defined variable without declaring it or initializing it. If you refer to a variable that has not been initialized, it has a value of NULL and a type of string. SELECT @var_any_var_name You can initialize a variable … Read more

How do I split a delimited string so I can access individual items?

I don’t believe SQL Server has a built-in split function, so other than a UDF, the only other answer I know is to hijack the PARSENAME function: SELECT PARSENAME(REPLACE(‘Hello John Smith’, ‘ ‘, ‘.’), 2) PARSENAME takes a string and splits it on the period character. It takes a number as its second argument, and … Read more

MySQL select 10 random rows from 600K rows fast

A great post handling several cases, from simple, to gaps, to non-uniform with gaps. http://jan.kneschke.de/projects/mysql/order-by-rand/ For most general case, here is how you do it: SELECT name FROM random AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM random)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 1 This supposes … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)