Java 如何在Oracle中添加图像?
我目前正在开发一个需要图像的应用程序,因此我尝试使用blob和clob变量在Oracle中通过SQL查询插入图像,但我无法完成此过程,而且我正在使用JAVA技术进行此操作。以下是解决您问题的简单方法:Java 如何在Oracle中添加图像?,java,database,image,Java,Database,Image,我目前正在开发一个需要图像的应用程序,因此我尝试使用blob和clob变量在Oracle中通过SQL查询插入图像,但我无法完成此过程,而且我正在使用JAVA技术进行此操作。以下是解决您问题的简单方法: FileInputStream fis; try { // Load JDBC driver "com.mysql.jdbc.Driver" Class.forName("oracle.jdbc.driver.OracleDriver"); /* C
FileInputStream fis;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("oracle.jdbc.driver.OracleDriver");
/* Create a connection by using getConnection() method that takes
parameters of string type connection url, user name and password to
connect to database. */
String connectionUrl = "your connection url";
String userName = "connecting database username";
String password = "corresponding password";
connection = DriverManager.getConnection(connectionUrl ,userName , password);
// create a file object for image by specifying full path of image as parameter.
File image = new File("C:/image.jpg");
/* prepareStatement() is used for create statement object that is
used for sending sql statements to the specified database. */
psmnt = connection.prepareStatement("insert into save_image(name, city, image) values(?,?,?)");
psmnt.setString(1,"name");
psmnt.setString(2,"city");
fis = new FileInputStream(image);
psmnt.setBinaryStream(3, (InputStream)fis, (int)(image.length()));
/* executeUpdate() method execute specified sql query. Here this query
insert data and image from specified address. */
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
} else {
System.out.println("unsucessfull to upload image.");
}
} catch (Exception e){
//log useful information
}
finally{
if (fis != null) {
fis.close();
}
if(psmnt != null){
psmnt.close();
}
if (connection!= null && !connection.isClosed()) {
connection.close();
}
}
以前也有人问过类似的问题。。。。看看。。。你试过什么?这只是一个谷歌搜索得到你想要的东西的问题……)