add gitignore

This commit is contained in:
2019-02-23 20:07:38 +03:00
parent f3228de6a2
commit 1ea8433649
7 changed files with 173 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import javax.xml.ws.Endpoint;
public class App
{
public static void main( String[] args )
{
String url = "http://localhost:8080/PersonService";
Endpoint.publish(url, new PersonWebService());
}
}
+30
View File
@@ -0,0 +1,30 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConnectionUtil {
private static final String JDBC_URL = "jdbc:postgresql://192.168.1.119:5432/postgres";
private static final String JDBC_USER = "postgres";
private static final String JDBC_PASSWORD = "qwerty";
static {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(PostgreSQLDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Connection getConnection() {
Connection connection = null;
try {
connection = DriverManager.getConnection(JDBC_URL, JDBC_USER,
JDBC_PASSWORD);
} catch (SQLException ex) {
Logger.getLogger(ConnectionUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return connection;
}
}
+39
View File
@@ -0,0 +1,39 @@
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Person {
private String name;
private String surname;
private int age;
public Person() {
}
public Person(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" + "name=" + name + ", surname=" + surname + ", age=" + age + '}';
}
}
+34
View File
@@ -0,0 +1,34 @@
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@WebService(serviceName = "PersonService")
public class PersonWebService {
@Resource(lookup = "jdbc/ifmo-ws")
private DataSource dataSource;
@WebMethod(operationName = "getPersons")
public List<Person> getPersons() {
PostgreSQLDAO dao = new PostgreSQLDAO(getConnection());
List<Person> persons = dao.getPersons();
return persons;
}
private Connection getConnection() {
Connection result = null;
try {
result = dataSource.getConnection();
} catch (SQLException ex) {
Logger.getLogger(PersonWebService.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
}
+38
View File
@@ -0,0 +1,38 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
* Created by artemsolonin on 12.05.2017.
*/
public class PostgreSQLDAO {
public PostgreSQLDAO(Connection connection) {
}
public List<Person> getPersons(){
List<Person> persons = new ArrayList<>();
try(Connection connection = ConnectionUtil.getConnection()){
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM persons");
while (rs.next()){
String name = rs.getString("name");
String surname = rs.getString("surname");
int age = rs.getInt("age");
Person person = new Person(name,surname,age);
persons.add(person);
}
}
catch (SQLException se)
{
se.printStackTrace();
}
return persons;
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
+16
View File
@@ -0,0 +1,16 @@
<%--
Created by IntelliJ IDEA.
User: svek
Date: 2019-02-23
Time: 19:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
$END$
</body>
</html>