Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.PageAttributes.MediaType;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.ws.rs.client.Client;
- import javax.ws.rs.client.ClientBuilder;
- import javax.ws.rs.client.Invocation;
- import javax.ws.rs.client.WebTarget;
- import org.glassfish.jersey.client.ClientConfig;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import javafx.application.Platform;
- import javafx.scene.media.Media;
- public class DataPipe {
- private Connection conn;
- public static void main(String[] args) {
- DataPipe dp = new DataPipe();
- try {
- dp.openConnection();
- dp.getOrderData();
- dp.closeConnection();
- } catch (SQLException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private void closeConnection() throws SQLException {
- conn.rollback();
- conn.close();
- System.out.println("Verbindung geschlossen");
- }
- private void openConnection() throws SQLException, ClassNotFoundException {
- try {
- // DriverManager.registerDriver(n);
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- conn = DriverManager.getConnection("jdbc:sqlserver://db1.institut-vaust.de:1433; databaseName=mdda", "mdda",
- "mdda");
- conn.setAutoCommit(false);
- conn.setTransactionIsolation(4);
- } catch (SQLException e) {
- e.printStackTrace();
- Platform.exit();
- }
- System.out.println("Verbindung hergestellt");
- }
- public void getOrderData() throws SQLException{
- PreparedStatement stmt = conn.prepareStatement("SELECT [Auftrags-ID], [Auftragsstatus-ID], Zeitstempel FROM Auftragsstatusverlauf");
- // PreparedStatement stmt = conn.prepareStatement("Select * from Auftrag");
- ResultSet rset = stmt.executeQuery();
- JSONArray array = new JSONArray();
- while(rset.next()){
- JSONObject obj = new JSONObject();
- obj.put("Zeit", rset.getDate("Zeitstempel"));
- obj.put("StatusID", rset.getInt("Auftragsstatus-ID"));
- System.out.println(obj.toString());
- array.put(obj);
- }
- }
- public void convertToJSONArray(){
- JSONArray array = new JSONArray();
- }
- // public void createConnectionToNUX(){
- // ClientConfig config = new ClientConfig();
- //
- // Client client = ClientBuilder.newClient(config);
- //
- // WebTarget target = client.target(/*hier die IP einfügen*/).path(/*hier den Path einfügen*/).path(/*hier den Service einfügen*/);
- //
- // Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement