Wednesday 19 July 2017

How to run jdbc program in command prompt in linux

                In this post, we will see how to run jdbc program in terminal or command prompt in Linux. Here we have used mysql database.

Watch following video:

                Follow the following steps.

1. You need to create user, database and table in mysql database. You need to grant privileges to the user. For details, check this post .

                     We have to download mysql-connector.jar file. We can download it from the link Extract zip file and save it at location /usr/share/java.              

                     To run jdbc program on terminal in Linux, you need to edit .bashrc file. You will get .bashrc file in following location

/home/[user name]/.bashrc


parag@parag-Inspiron-N4010:~$ gedit /home/parag/.bashrc

Then add following line in .bashrc file:

export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector.jar

Save it and restart the system.

3. Write a jdbc program as per your requirement.

                Check jdbc program for retrieving data in this post
                Check jdbc program for inserting data into table in this post

4. Open terminal, go the location where you have saved your program, compile code by using javac and run it by java command.


parag@parag-Inspiron-N4010:~/Desktop/prog$ javac 
parag@parag-Inspiron-N4010:~/Desktop/prog$ java jdbcinsert
3101 te pict pune 

4301 be gcoe amravati 

1201 se vjti mumbai 

No comments:

Post a Comment