Advertisement
Guest User

ML

a guest
Jun 29th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1. import java.awt.PageAttributes.MediaType;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import javax.ws.rs.client.Client;
  9. import javax.ws.rs.client.ClientBuilder;
  10. import javax.ws.rs.client.Invocation;
  11. import javax.ws.rs.client.WebTarget;
  12.  
  13. import org.glassfish.jersey.client.ClientConfig;
  14. import org.json.JSONArray;
  15. import org.json.JSONObject;
  16.  
  17. import javafx.application.Platform;
  18. import javafx.scene.media.Media;
  19.  
  20. public class DataPipe {
  21.     private Connection conn;
  22.  
  23.     public static void main(String[] args) {
  24.         DataPipe dp = new DataPipe();
  25.         try {
  26.             dp.openConnection();
  27.             dp.getOrderData();
  28.             dp.closeConnection();
  29.         } catch (SQLException | ClassNotFoundException e) {
  30.             e.printStackTrace();
  31.         }
  32.  
  33.     }
  34.  
  35.     private void closeConnection() throws SQLException {
  36.         conn.rollback();
  37.         conn.close();
  38.         System.out.println("Verbindung geschlossen");
  39.        
  40.     }
  41.  
  42.     private void openConnection() throws SQLException, ClassNotFoundException {
  43.         try {
  44. //          DriverManager.registerDriver(n);
  45.  
  46.                     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  47.                     conn = DriverManager.getConnection("jdbc:sqlserver://db1.institut-vaust.de:1433; databaseName=mdda", "mdda",
  48.                     "mdda");
  49.                    
  50.                     conn.setAutoCommit(false);
  51.                     conn.setTransactionIsolation(4);
  52.         } catch (SQLException  e) {
  53.             e.printStackTrace();
  54.             Platform.exit();
  55.         }
  56.                 System.out.println("Verbindung hergestellt");
  57.  
  58.     }
  59.    
  60.     public void getOrderData() throws SQLException{
  61.         PreparedStatement stmt = conn.prepareStatement("SELECT [Auftrags-ID], [Auftragsstatus-ID], Zeitstempel FROM Auftragsstatusverlauf");
  62.  
  63. //      PreparedStatement stmt = conn.prepareStatement("Select * from Auftrag");
  64.        
  65.         ResultSet rset = stmt.executeQuery();
  66.        
  67.         JSONArray array = new JSONArray();
  68.        
  69.        
  70.         while(rset.next()){
  71.             JSONObject obj = new JSONObject();
  72.            
  73.             obj.put("Zeit", rset.getDate("Zeitstempel"));
  74.             obj.put("StatusID", rset.getInt("Auftragsstatus-ID"));
  75.            
  76.             System.out.println(obj.toString());
  77.            
  78.             array.put(obj);
  79.         }
  80.     }
  81.    
  82.     public void convertToJSONArray(){
  83.         JSONArray array = new JSONArray();
  84.        
  85.     }
  86.    
  87.    
  88. //  public void createConnectionToNUX(){
  89. //      ClientConfig config = new ClientConfig();
  90. //     
  91. //      Client client = ClientBuilder.newClient(config);
  92. //     
  93. //      WebTarget target = client.target(/*hier die IP einfügen*/).path(/*hier den Path einfügen*/).path(/*hier den Service einfügen*/);
  94. //     
  95. //      Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
  96. //  }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement