import java.sql.*;import java.util.*;import java.sql.DriverManager;// return true if some records satisfy the condition, otherwase, false.public Boolean IsExifPhotoIdTimeLongitudeLatitude( String photoId, String time, String longitude, String latitude ){Connection con = null;String url = "";String driver = "";Statement stmt = null;String query = "";// your database table nameString targetSheet = "db_table_name";ResultSet result = null;Boolean hasRecord = false;// your queryquery = "SELECT * FROM `"+ targetSheet +"` WHERE photoId='" + photoId + "' AND time='" + time + "' AND longitude='" + longitude + "' AND latitude='" + latitude + "'";try{// connect to mysql databaseurl = "jdbc:mysql://127.0.0.1:3306/database_name";driver = "com.mysql.jdbc.Driver";p = new Properties();Class.forName(driver).newInstance();con = DriverManager.getConnection(url, "user_name", "pass_word");// create statementstmt = con.createStatement();// execute your queryresult = stmt.executeQuery(query);// result.first() will return false if there is no record// Important: executeQuery never return nullif( result.first() ){hasRecord = true;}}catch( Exception e ) {e.printStackTrace();}finally {}return hasRecord;}
I wanted to setup MySQL to use utf-8 on the MAMP installation on my Mac. I tried the instructions from this article: http://cameronyule.com/2008/07/configuring-mysql-to-use-utf-8/ However, I kept getting error messages that are similar to this one [ERROR] /Applications/MAMP/Library/bin/mysqld: unknown variable 'default-collation=utf8_general_ci' I did some search and realized that several variables are deprecated. Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html Therefore, I added the following lines into /Applications/MAMP/conf/my.cnf [mysql] character-set-server=utf8 [client] character-set-server=utf8 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci init-connect='SET NAMES utf8' I restarted the server and mysql run successfully with relevant variables being set correctly. In the "Variables" tab under phpMyAdmin interface (ex. http://localhost:8888/MAMP/?language=English) character set c
Comments