将上述修改放入整段代码中
时间: 2024-04-17 12:24:35 浏览: 89
侠众道服务端_侠众道修改_千年服务端_千年_千年1源代码_千年1
5星 · 资源好评率100%
下面是将前面提到的修改应用到整段代码中的示例:
```java
import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class HiveBinaryTranslate extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Task<BufferedImage> queryTask = new Task<BufferedImage>() {
@Override
protected BufferedImage call() throws Exception {
String CONNECTION_URL = "jdbc:hive2://192.168.88.100:10000/default";
String USERNAME = "root";
String PASSWORD = "123456";
String JDBC_DRIVER = "org.apache.hive.jdbc.HiveDriver";
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(CONNECTION_URL, USERNAME, PASSWORD);
Statement stmt = conn.createStatement();
String sql = "SELECT data FROM picture_01 WHERE dt = '2023-07-13'";
ResultSet rs = stmt.executeQuery(sql);
rs.next();
InputStream inputStream = rs.getBinaryStream("data");
BufferedImage bufferedImage = ImageIO.read(inputStream);
rs.close();
stmt.close();
conn.close();
inputStream.close();
return bufferedImage;
}
};
queryTask.setOnSucceeded(event -> {
BufferedImage bufferedImage = queryTask.getValue();
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
ImageView imageView = new ImageView(image);
Scene scene = new Scene(imageView.getParent());
primaryStage.setTitle("Image Viewer");
primaryStage.setScene(scene);
primaryStage.show();
});
queryTask.setOnFailed(event -> {
Throwable exception = queryTask.getException();
// 处理异常
exception.printStackTrace();
});
Thread queryThread = new Thread(queryTask);
queryThread.start();
}
}
```
请确保你已经添加了必要的依赖项,如 Hive JDBC 驱动程序和 JavaFX 库。此外,还需要根据实际情况修改连接数据库的参数。
希望这次能够顺利运行!如果你还有其他问题,请随时提问。
阅读全文