воскресенье, 7 ноября 2010 г.

Sorting rubbish in downloads (linux)

#!/bin/bash
echo "Раскидываем помойку по категориям.."
test -d Documents || mkdir Documents
mv *.doc *.docx *.odf *.pdf ./Documents/
test -d Databases || mkdir Databases
mv *.sql ./Databases/
test -d Roms || mkdir Roms
mv *.7z *.gen ./Roms/
test -d Music || mkdir Music
mv *.mp3 ./Music/
test -d Package || mkdir Packages
mv *.deb *.rpm ./Packages/
test -d Text || mkdir Text
mv *.txt *.html ./Text
test -d Sources || mkdir Sources
mv *.tar* ./Sources/
test -d Archives || mkdir Archives
mv *.zip *.rar ./Archives/
test -d Images || mkdir Images
mv *.JPG *.PNG *.png *.jpg *.gif *.GIF ./Images/
test -d Video || mkdir Video
mv *.avi *.flv *.mp4 ./Video/
test -d ISO || mkdir ISO
mv *.ISO *.iso ./ISO/
Run this script in folder, where many files!

понедельник, 1 ноября 2010 г.

MySQL: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Recently I got next exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
Communications link failure 
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

I looking into google, but got no answer, except for "check your server", "check port of your server", "check localhost at /etc/hosts" and some other unavailing stuff.
Problem was in my code, I feel, that I'm Great Indian Coder, then detect it.
Connection conn = DriverManager.getConnection("jdbc:mysql://" + 
app.sql.settings.constants.getHost() +
app.sql.settings.constants.getPort() +
app.sql.settings.constants.getDb() +
app.sql.settings.constants.getUser() +
app.sql.settings.constants.getPassword());

I wrote it too fast and I was distracted on something and don't noticed it. Correct code is:
Connection conn = DriverManager.getConnection("jdbc:mysql://" + 
app.sql.settings.constants.getHost() + ":" +
app.sql.settings.constants.getPort() + "/" +
app.sql.settings.constants.getDb(),
app.sql.settings.constants.getUser(),
app.sql.settings.constants.getPassword());

because correct format of getConnection's parameters is:
jdbc:mysql://host:port/db, user, password

I will be glad if it will help you.