Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.scene.image.Image;
- import javax.imageio.ImageIO;
- import java.awt.image.BufferedImage;
- import java.io.InputStream;
- import java.sql.*;
- public class MysqlConnect extends Image {
- /*
- * set the default variables for mysql connection
- * */
- private static final String url ="";
- private static final String user = "";
- private static final String password = "";
- public MysqlConnect(String s) {
- super(s);
- }
- public static BufferedImage main()
- {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(url, user, password);
- System.out.println("Success");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("select * from images");
- BufferedImage image = null;
- if (!rs.next()) {
- java.sql.Blob blob = rs.getBlob(2);
- InputStream in = blob.getBinaryStream();
- image = ImageIO.read(in);
- }
- con.close();
- System.out.println("reached here");
- return image;
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
- }
- import javafx.scene.image.ImageView;
- public class Controller extends Main {
- private ImageView imageView;
- public void SubmitButtonClicked(){System.out.println("it is Submitted ");}
- public void NextButtomClicked()
- {
- MysqlConnect image = new MysqlConnect("one");
- imageView.setImage(image);
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.geometry.Insets?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.TextField?>
- <?import javafx.scene.image.ImageView?>
- <?import javafx.scene.layout.BorderPane?>
- <?import javafx.scene.layout.HBox?>
- <?import javafx.scene.layout.Region?>
- <?import javafx.scene.layout.VBox?>
- <BorderPane prefHeight="576.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
- <bottom>
- <VBox prefHeight="98.0" prefWidth="600.0" BorderPane.alignment="CENTER">
- <children>
- <HBox prefHeight="159.0" prefWidth="648.0">
- <children>
- <TextField promptText="Name:">
- <HBox.margin>
- <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
- </HBox.margin>
- </TextField>
- <Region HBox.hgrow="ALWAYS" />
- <Button mnemonicParsing="false" text="Decline">
- <HBox.margin>
- <Insets left="25.0" right="25.0" top="50.0" />
- </HBox.margin>
- </Button>
- <Button layoutX="181.0" layoutY="10.0" mnemonicParsing="false" onAction="#SubmitButtonClicked" text="Submit">
- <HBox.margin>
- <Insets right="10.0" top="50.0" />
- </HBox.margin>
- </Button>
- </children>
- </HBox>
- </children>
- </VBox>
- </bottom>
- <left>
- <ImageView fx:id="imageView" fitHeight="341.0" fitWidth="284.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER_RIGHT">
- <BorderPane.margin>
- <Insets bottom="20.0" left="20.0" right="20.0" top="8.0" />
- </BorderPane.margin>
- </ImageView>
- </left>
- <top>
- <HBox prefHeight="94.0" prefWidth="600.0" BorderPane.alignment="CENTER">
- <children>
- <Button mnemonicParsing="false" prefHeight="30.0" prefWidth="74.0" text="Previous">
- <HBox.margin>
- <Insets left="10.0" right="10.0" top="8.0" />
- </HBox.margin>
- </Button>
- <Region prefHeight="166.0" prefWidth="144.0" />
- <Button mnemonicParsing="false" onAction="#NextButtomClicked" prefHeight="30.0" prefWidth="74.0" text="Next">
- <HBox.margin>
- <Insets top="8.0" />
- </HBox.margin>
- </Button>
- </children>
- </HBox>
- </top>
- </BorderPane>
Add Comment
Please, Sign In to add comment