REST API WITH POSTGRES DATABASE
- First i started working on eclipse mars ,but i got lot of errors even at sample program that given in https://www.tutorialspoint.com/restful/restful_first_application.htm. Main drop back of eclipse is we need to add many jersey files and jdk 1.7 , tomcat into application
- Then i move on to netbeans because i contain in bulid jersey files, jdk , tomcat.
Netbeans setup Environment
Give Executable permission : $ chmod +x ~/Downloads/netbeans-8.1*.sh
Start Installer : $ cd ~/Downloads && ./netbeans-8.1*.sh
Set JDK location : Browse to JDK location
-----------------------------------------------------------------------
Tomcat server setup Environment
$ tar –zxvf apache-tomcat-8.5.5.tar.gz
$ cd apache-tomcat-8.5.5/bin/
To start tomcat server:
$ ./startup.sh
Browse Tomcat running or not:
Localhost:8080
To stop tomcat server:
$ ./shutdown.sh
To change tomcat users name and password :
$ gedit /path/to/apache-tomcat-8.5.5/conf/tomcat-users.xml
To change server port number:
$ gedit /path/to/apache-tomcat-8.5.5/conf/server.xml
------------------------------------------------------------------------------------------------------------------------
Create Rest Api application
File=>New Project=>Java Web=>Web Application=>Next => Enter Project Name => next=>Select Server (Either GlassFish/Tomcat) => next=>Finish.
-----------------------------------------------------------------------
Postgres setup Environment
1. sudo apt-get update
2. sudo apt-get install postgresql postgresql-contrib
2. sudo apt-get install postgresql postgresql-contrib
3. Create a user account called postgres which is associated to postgres role
sudo -i -u postgres
4. Postgre is prompt by immediately typing
psql
5. For Exit Postgres type
\q
6. For enter into Postgres use this keyword
sudo -u postgres psql postgres
7. For creating database password
\password postgres
8. Create database in Postgres
create database databasename
9. For connecting database
\c databasename
10. For disconnecting database
\q
----------------------------------------------------------------------------------------------------
SETTING PASSWORD FOR POSTGRES:
supranimbus04@supranimbus04-Inspiron-3250:~$ sudo -u postgres psql
Password:
It will ask password , If the configuration of file $ sudo gedit /etc/postgresql/9.3/main/pg_hba.conf
local all postgres md5
If we don’t need to password , then change configuration of the
$ sudo gedit/etc/postgresql/9.3/main/pg_hba.conf
local all postgres peer
If any changes made into $ sudo gedit/etc/postgresql/9.3/main/pg_hba.conf file , Then you need to restart to the service
sudo service postgresql restart
--------------------------------------------------------------------------------------------------------
To view postgres status
$ sudo service postgresql status
--------------------------------------------------------------------------------------------------------
Creating table in postgres
- Create table tablename ();
postgres=# create table testtbl(id int primary key not null,name char(30));
2. To view list of tables
- \d - is to view list of new tables that are created
- \dt - is to view list of tables that are present in database
3. To delete table
Drop table tablename;
------------------------------------------------------------------------------------------------------
For JDBC connection
- https://jdbc.postgresql.org/download.html visit this link to download “JDBC3 Postgresql Driver, Version 9.3-1103” driver
- Now add this driver into netbeans libraries
- For reference visit this link
http://java2db.com/java-integrations/jdbc-with-postgresql-using-myeclipse-and-netbeans
--------------------------------------------------------------------------------------------------------
Employee details program using Rest api with postgres database
Access.java
DataBase.java
Employee.java
AccessManager.java
EmployeeSevice.java
Output
JSON file will be displayed under this URL
No comments:
Post a Comment