Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author Admin
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int wierzcholekKoncowy = Integer.parseInt(args[1]); //końcowy wierzchołek grafu
- int iloscWierzcholkow = 0; //liczba wierzchołków
- try {
- String database = args[0];
- Connection conn = DriverManager.getConnection(database);
- PreparedStatement stmt = conn.prepareStatement("SELECT x, y, p FROM GTable");
- stmt.execute();
- ResultSet r = stmt.getResultSet();
- List<Path.Punkt> pl = new ArrayList<>();
- while(r.next()){
- Path.Punkt p = new Path.Punkt();
- p.setX(r.getInt("x"));
- p.setY(r.getInt("y"));
- p.setP(r.getFloat("p"));
- pl.add(p);
- }
- for(Path.Punkt p : pl){
- if(p.getX()>iloscWierzcholkow)
- iloscWierzcholkow=p.getX();
- if(p.getY()>iloscWierzcholkow)
- iloscWierzcholkow=p.getY();
- }
- Path pg = new Path(iloscWierzcholkow, wierzcholekKoncowy-1, pl);
- pg.obliczKoszt();
- float koszt = pg.getKoszty();
- System.out.format("Koszt: %.3f", koszt);
- }
- catch(SQLException ex){
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement