Browse Source

added working get statment from DB

exception_work
Nicholas Caughey 3 years ago
parent
commit
6f3da3e158
  1. 31
      src/main/java/rest/CreateGetResource.java

31
src/main/java/rest/CreateGetResource.java

@ -6,6 +6,10 @@ import java.util.Set;
import dto.ScanObj;
import dto.ConnectDB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -19,6 +23,8 @@ import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import java.sql.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
@ -32,18 +38,8 @@ public class CreateGetResource {
public CreateGetResource() {
ConnectDB connectDB = new ConnectDB();
connectDB.connect();
// Connection conn = null;
// try {
// conn = DriverManager.getConnection(url, user,password);
// System.out.println("connected to PGSQL");
// } catch (SQLException e) {
// System.out.println(e.getMessage());
// }
//example used to show the get obviously needs deleting
Scans.add(new ScanObj("a","a","a","a","a","a","a","a","a","a"));
}
@ -51,8 +47,19 @@ public class CreateGetResource {
@Path("/{scanId}")
public Set<ScanObj> list(@PathParam("scanId") String scanId) {
//use to return specific scanIds just use usual fetch from sets, will be querying hte db directly here
try {
ConnectDB connectDB = new ConnectDB();
Connection conn = connectDB.connect();
String sql = "SELECT" + scanId + "FROM scans";
PreparedStatement preparedStatment = conn.prepareStatement(sql);
preparedStatment.executeQuery(sql);
} catch (SQLException e){
System.out.println("failed");
}
// conn.
System.out.println(Scans);
System.out.println(scanId);
return Scans;
}
}
Loading…
Cancel
Save