public ArrayList<AnchorPane> getProduct() throws SQLException, ClassNotFoundException{
String Sql = "Select * from Product";
try {
Statement statement = getDbConnection().createStatement();
ResultSet resultSet = statement.executeQuery(Sql);
ArrayList<AnchorPane> product = new ArrayList<>();
while (
resultSet.next ()){
AnchorPane hBox = new AnchorPane();
Background background = new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY));
String path =resultSet.getString("ProductPhoto");
Image image = new Image(path);
ImageView imageView = new ImageView(image);
imageView.setFitHeight(100);
imageView.setFitWidth(100);
imageView.setLayoutX(10);
imageView.setLayoutY(10);
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import java.io.File;
import java.net.MalformedURLException;
import java.sql.*;
import java.util.ArrayList;
//import com.example.demo.Tools.ProductListMetaData;
import javafx.scene.image.Image;
import javafx.scene.layout.BackgroundFill;
public class DB {
private final String Host="192.168.13.100";
private final String Post="3306";
private final String DbName="user47";
private final String Login="user47";
private final String Password="95157";
private Connection DBconn=null;
private Connection getDBconn() throws SQLException, ClassNotFoundException{
String connStr= "jdbc:mysql://" + Host + ":" + Post + "/" + DbName + "?characterEncoding=UTF8";
Class.forName("com.mysql.cj.jdbc.Driver");
DBconn=DriverManager.getConnection(connStr, Login, Password);
return DBconn;
}
public ArrayList<AnchorPane> getProduct() throws SQLException, ClassNotFoundException{
String Sql = "Select * from Tovar";
try{
Statement statement= getDBconn().createStatement();
ResultSet resultSet = statement.executeQuery(Sql);
ArrayList<AnchorPane> product = new ArrayList<>();
while (resultSet.next()){
AnchorPane hBox = new AnchorPane();
Background background= new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY));
String path = resultSet.getString("Kartinka");
File file=new File(path);
System.out.println(path);
String xz=file.toURL().toString();
Image image =new Image(xz);
ImageView imageView=new ImageView(image);
imageView.setFitHeight(100);
imageView.setFitWidth(100);
imageView.setLayoutX(10);
imageView.setLayoutY(10);
// ProductListMetaData productListMetaData = new ProductListMetaData();
// productListMetaData.setName(resultSet.getString("ProductName"));
// hBox.setUserData(productListMetaData);
Label nameLabel = new Label(resultSet.getString("Tovarnaim"));
nameLabel.setLayoutX(130);
nameLabel.setLayoutY(10);
Label descriptionLabel=new Label("ÐпиÑание ÑоваÑа: "+resultSet.getString("Opis"));
descriptionLabel.setLayoutX(130);
descriptionLabel.setLayoutY(25);
// if (resultSet.getString("ProductQuantyInStock").equals("0")){
// hBox.setBackground(background);
// }
hBox.getChildren().add(imageView);
hBox.getChildren().add(nameLabel);
hBox.getChildren().add(descriptionLabel);
product.add(hBox);
}
return product;
}catch(SQLException e) {
throw new RuntimeException(e);
}catch (ClassNotFoundException e){
throw new RuntimeException(e);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}