從MySQL數據庫檢索多個團塊圖像我很新的Java和MySQL和我想檢索多個(很多!)斑點圖像。
我需要某種循環查詢才能瀏覽所有圖像。Java的 - 如何從MySQL
我開始用教程(http://www.roseindia.net/java/java-get-example/get-blob.shtml),這對我的偉大工程。 - 請記住,我正在將圖片直接送到我的電腦。
你們是否有關於如何擴大現有的代碼,以便檢索不是一個而是多個圖像有什麼建議?
這是我使用的代碼:
class GetBlob {
FileOutputStream image;
Connection con = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet res = null;
StringBuffer query = null;
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "portal";
String userName = "root";
String password = "xxxx";
public GetBlob() {
try {
Class.forName(driverName);
con = DriverManager.getConnection(url + dbName, userName, password);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from pictures where id='1'");
if (rs.next()) {
Blob test = rs.getBlob("picture");
InputStream x = test.getBinaryStream();
int size = x.available();
OutputStream out = new FileOutputStream("/Users/User/Desktop/anu2.jpg");
byte b[] = new byte[size];
x.read(b);
out.write(b);
}
} catch (Exception e) {
System.out.println("Exception :" + e);
} finally {
try {
stmt.close();
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
public static void main(String args[]) throws IOException {
GetBlob blob = new GetBlob();
}
}
什麼類型的id'int'或'varchar'? –
哦,對不起,忘了 - int –
你應該通過[Oracle JDBC教程](https://docs.oracle.com/javase/tutorial/jdbc/basics/index.html)。 – vanje