JDBC on LINUX
I've though that JDBC is something significant for build an application. But today we won't talk about JDBC on windows, we'll talk about how to connect java programing with database management system on linux... In other word, it's mean that we won't talk about win32 anymore. Ha3...
anyway, if we want to build an application that has relation with database on linux (with java programing too) it' will take a several time... and there's some steps to do those things correctly. But now, maybe you ask for me “how to connect java language programming with database management system ?” hu... its simple.... (ha3.. sounds good !!!) .but it won't be OK, if you don't follow these steps.
and the following steps is :
Oh,my god... I forgot...
I have choose mysql as database management system that we will use...
STEP 1
install mysql on your UNIX system...
$> sudo apt-get install mysql
STEP 2
after you install mysql on your UNIX system, you must configure that...
login as root to mysql
$>mysql -uroot -pripsta
mysql>
you must create database that u need...
(remember, in UNIX system... you can't create database in local user mode)
mysql> create database agusta;
STEP 3
if you have made a database before...
next, you must set that database if you want to that database can use by local user mode.
mysql> GRANT ALL PRIVILEGES ON agusta.* TO dude@localhost IDENTIFIED BY 'ripsta';
mysql> GRANT ALL PRIVILEGES ON agusta.* TO dude@localhost.localdomain IDENTIFIED BY 'ripsta';
STEP 4
if you have done with that without error, so you must take step deeper...
OK, you need java connector to mysql...
you can download from this URL :
if you have downloaded the connector that appropriate, lets extarct the *.zip file to directory you need.
For example :
/home/dude/java/conn/
OK lets imagine that the coonector has extracted in the directory...
STEP 5
ok this is the technically steps that you must learn...
this is java part...
import java.sql.*;
/**
*
* @author dude
*/
public class Database {
public static void main(String[] args)
{
Connection conn=null;
try{
String url="jdbc:mysql://localhost:3306/agusta";
String user="dude";
String pwd="ripsta";
String jdbcDriver = "org.gjt.mm.mysql.Driver";
Class.forName(jdbcDriver);
System.out.println("trying to make a connection to "+url+" with user "+user+" and password "+pwd+" proccessing.......");
conn = DriverManager.getConnection(url,user,pwd);
System.out.println("success...");
}
catch(Exception e)
{
System.out.println("connection error");
System.out.println(e.getMessage());
}
}
}
copy this source code to your text editor, and save the file as Database.java into the active directory (/home/dude/java/conn/) <--- it's urgent...
STEP 6
ok now, we must chek all things we've done...
lets change the Classpath first...
in the terminal, set directory as the active directory...
$>cd /home/dude/java/conn/
$>export CLASSPATH=.
$>export CLASSPATH=$CLASSPATH:/home/dude/java/conn/mysql-connector-java-3.1.10/mysql-connector-java-3.1.10-bin.jar
$>javac Database.java
$>java Database
well... we will happy now...
the compilation will success without runtime error...
if you confuse, you can check the video tutorial