JavaTechie

Its all about Technology

Mysql+Date functions January 29, 2009

Filed under: Mysql — javatechie @ 9:39 am
Tags: ,

Example’s that uses date functions.

The following query selects all rows with a date_col value from within the last 30 days:
mysql> SELECT something FROM tbl_name
-> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col;

ADDDATE(date,INTERVAL expr unit), ADDDATE(expr,days)
SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY);
-> ‘2008-02-02′
SELECT ADDDATE(‘2008-01-02′, INTERVAL 31 DAY);
-> ‘2008-02-02′
mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
-> ‘Sunday October 2009′
mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
-> ‘22:23:00′
mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',

-> '%D %y %a %d %m %b %j');
-> ‘4th 00 Thu 04 10 Oct 277′
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
-> '%H %k %I %r %T %S %w');

-> ‘22 22 10 10:23:00 PM 22:23:00 00 6′
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
-> ‘1998 52′
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
-> ‘00′
mysql> SELECT EXTRACT(YEAR FROM '2009-07-02');
-> 2009
mysql> SELECT EXTRACT(YEAR_MONTH FROM '2009-07-02 01:02:03');
-> 200907
mysql> SELECT EXTRACT(DAY_MINUTE FROM '2009-07-02 01:02:03');

-> 20102
mysql> SELECT EXTRACT(MICROSECOND
-> FROM '2003-01-02 10:30:00.000123');
-> 123

 

HOW TO Subversion+Apache on Fedora January 29, 2009

Filed under: Apache — javatechie @ 5:30 am
Tags: , ,

HOW TO Subversion+Apache on Fedora

To learn or use Subversion, please read the book.

To install subversion run below commands:

# yum install subversion
# yum install mod_dav_svn

Then you need to setup at least one repository to test it.

Here create the folders..

# mkdir /svn
# mkdir /svn/repos
# mkdir /svn/users
# mkdir /svn/permissions

repos – will contain all the projects

users – will contain all the user configs

permissions – will contain all the user permissions

We need to give these folders the proper permissions apache user permissions so that apache can write files on repos.

# chown -R apache.apache /svn

Then you can create repository using subversion cmd svnadmin.

# svnadmin create /svn/repos/project1

You can create multiple project repos under repos folder.

To setup apache server.

You may already have this subversion config file installed in conf.d folder otherwise you can create a new apache include file that will hold all configurations.

# vi /etc/httpd/conf.d/subversion.conf

This file need to contain something like this to serve the repository through apache:


LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /svn/>
DAV svn
SVNPath /svn/repos
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /svn/users/passwords
Require valid-user
AuthzSVNAccessFile /svn/permissions/svnauthz.conf

</Location>

We need to create some files so that this config will work properly. The first is htpasswd file which will contain all the usernames nad passwords which i named “/svn/users/passwords”.

# htpasswd -cb /svn/users/passwords username password

Next you need to create the svnauth file.

# vi /svn/permissions/svnauthz.conf

Inside place a list of users who have access to files:

[/]

username = rw

The “rw” states that this user has read/write access to the root repository /.

Restart your web server and you should be done.

service httpd restart

Now you should access subversion repos as below.

http://www.websitename.com/svn/repos/

 

how to find the last insert id in java+mysql? January 23, 2009

Filed under: Java, Mysql — javatechie @ 1:32 pm
Tags: ,

JDBC 3.0 (MySQL is has a JDBC 3 compliant driver) method as such:

Statement stat = dbConn.createStatement();
Stat.executeUpdate(“Some insert statement here”);

ResultSet rs = stat.getGeneratedKeys();
Int insertedKeyValue = rs.getInt(1);

Rs.close();
Stat.close();