Guest User

Untitled

a guest
Mar 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.scene.image.Image;
  4.  
  5. import javax.imageio.ImageIO;
  6. import java.awt.image.BufferedImage;
  7. import java.io.InputStream;
  8. import java.sql.*;
  9.  
  10.  
  11. public class MysqlConnect extends Image {
  12. /*
  13. * set the default variables for mysql connection
  14. * */
  15. private static final String url ="";
  16.  
  17. private static final String user = "";
  18.  
  19. private static final String password = "";
  20.  
  21. public MysqlConnect(String s) {
  22. super(s);
  23. }
  24.  
  25.  
  26.  
  27. public static BufferedImage main()
  28. {
  29. try {
  30. Class.forName("com.mysql.jdbc.Driver");
  31. Connection con = DriverManager.getConnection(url, user, password);
  32. System.out.println("Success");
  33.  
  34. Statement stmt = con.createStatement();
  35. ResultSet rs = stmt.executeQuery("select * from images");
  36.  
  37. BufferedImage image = null;
  38. if (!rs.next()) {
  39. java.sql.Blob blob = rs.getBlob(2);
  40. InputStream in = blob.getBinaryStream();
  41. image = ImageIO.read(in);
  42. }
  43.  
  44.  
  45. con.close();
  46. System.out.println("reached here");
  47. return image;
  48.  
  49.  
  50. } catch (Exception e)
  51. {
  52. e.printStackTrace();
  53. }
  54.  
  55. return null;
  56. }
  57.  
  58. }
  59.  
  60. import javafx.scene.image.ImageView;
  61.  
  62.  
  63. public class Controller extends Main {
  64.  
  65. private ImageView imageView;
  66.  
  67.  
  68.  
  69. public void SubmitButtonClicked(){System.out.println("it is Submitted ");}
  70.  
  71. public void NextButtomClicked()
  72. {
  73. MysqlConnect image = new MysqlConnect("one");
  74. imageView.setImage(image);
  75.  
  76. }
  77.  
  78. }
  79.  
  80. <?xml version="1.0" encoding="UTF-8"?>
  81.  
  82. <?import javafx.geometry.Insets?>
  83. <?import javafx.scene.control.Button?>
  84. <?import javafx.scene.control.TextField?>
  85. <?import javafx.scene.image.ImageView?>
  86. <?import javafx.scene.layout.BorderPane?>
  87. <?import javafx.scene.layout.HBox?>
  88. <?import javafx.scene.layout.Region?>
  89. <?import javafx.scene.layout.VBox?>
  90.  
  91. <BorderPane prefHeight="576.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
  92. <bottom>
  93. <VBox prefHeight="98.0" prefWidth="600.0" BorderPane.alignment="CENTER">
  94. <children>
  95. <HBox prefHeight="159.0" prefWidth="648.0">
  96. <children>
  97. <TextField promptText="Name:">
  98. <HBox.margin>
  99. <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
  100. </HBox.margin>
  101. </TextField>
  102. <Region HBox.hgrow="ALWAYS" />
  103. <Button mnemonicParsing="false" text="Decline">
  104. <HBox.margin>
  105. <Insets left="25.0" right="25.0" top="50.0" />
  106. </HBox.margin>
  107. </Button>
  108. <Button layoutX="181.0" layoutY="10.0" mnemonicParsing="false" onAction="#SubmitButtonClicked" text="Submit">
  109. <HBox.margin>
  110. <Insets right="10.0" top="50.0" />
  111. </HBox.margin>
  112. </Button>
  113. </children>
  114. </HBox>
  115. </children>
  116. </VBox>
  117. </bottom>
  118. <left>
  119. <ImageView fx:id="imageView" fitHeight="341.0" fitWidth="284.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER_RIGHT">
  120. <BorderPane.margin>
  121. <Insets bottom="20.0" left="20.0" right="20.0" top="8.0" />
  122. </BorderPane.margin>
  123.  
  124. </ImageView>
  125. </left>
  126. <top>
  127. <HBox prefHeight="94.0" prefWidth="600.0" BorderPane.alignment="CENTER">
  128. <children>
  129. <Button mnemonicParsing="false" prefHeight="30.0" prefWidth="74.0" text="Previous">
  130. <HBox.margin>
  131. <Insets left="10.0" right="10.0" top="8.0" />
  132. </HBox.margin>
  133. </Button>
  134. <Region prefHeight="166.0" prefWidth="144.0" />
  135. <Button mnemonicParsing="false" onAction="#NextButtomClicked" prefHeight="30.0" prefWidth="74.0" text="Next">
  136. <HBox.margin>
  137. <Insets top="8.0" />
  138. </HBox.margin>
  139. </Button>
  140. </children>
  141. </HBox>
  142. </top>
  143. </BorderPane>
Add Comment
Please, Sign In to add comment