将字符[]或字符串(url)保存为数据库中的图像(配置文件图片)? 有什么优点和缺点?将二进制[]或字符串(url)保存在数据库中的图像(配置文件图片)?
0
A
回答
0
你应该更喜欢URL而不是byte []。
主要原因是,并非每种语言在将图像存储到字节数组时都有相同的位模式。例如,java的字节是有符号的(范围是-128到127),而C#的字节是无符号的(范围是0到255)。这意味着,如果您使用C#将字符数组存储在字节数组中,平台将字节数组重新转换为图像必须是c#除了识别网络资源之外,URL是一个URI。正如你可以从它的名字上了解到它的平台是独立的Uniform Resource Locator
。用户可以在任何类型的平台中使用这些信息。
0
使用一滴保存在这里的数据库图像文件是在Java代码 创建表作为
CREATE TABLE save_image (
id int(5) NOT NULL auto_increment,
name varchar(25) default NULL,
city varchar(20) default NULL,
image blob,
Phone varchar(15) default NULL,
PRIMARY KEY (`id`)
);
的java这里的文件由用户保存图像
import java.sql.*;
import java.io.*;
class SaveImageToDatabase {
public static void main(String[] args) throws SQLException {
// declare a connection by using Connection interface
Connection connection = null;
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost
and database name is mahendra. */
String connectionURL = "jdbc:mysql://localhost:3306/mahendra";
/*declare a resultSet that works as a table resulted by execute a specified
sql query. */
ResultSet rs = null;
// Declare prepare statement.
PreparedStatement psmnt = null;
// declare FileInputStream object to store binary stream of given image.
FileInputStream fis;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* Create a connection by using getConnection() method that takes
parameters of string type connection url, user name and password to
connect to database. */
connection = DriverManager.getConnection(connectionURL, "root", "root");
// 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, Phone) "+ "values(?,?,?,?)");
psmnt.setString(1,"SmashCode");
psmnt.setString(2,"GPU");
psmnt.setString(4,"127001");
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 if found any exception during rum time.
catch (Exception ex) {
System.out.println("Found some error : "+ex);
}
finally {
// close all the connections.
connection.close();
psmnt.close();
}
}
}
可以检索图像您可能在这里提到这个网站here
我在这里主要使用代码希望我的工作让你开心大拇指我的回答如果你喜欢
相关问题
- 1. 我应该将图像二进制数据保存到数据库还是将图像保存为文件?
- 2. 将二进制图像数据复制到字符串中
- 3. 无法保存图表,“字符串或二进制数据将被截断”
- 4. 如何将图像保存到文件夹中,将二进制图像转换为字符串时
- 5. 将图像转换为二进制数据或Javascript中的字符串
- 6. 如何将二进制图像数据转换为图像文件并将其保存在文件夹中php
- 7. 错误,字符串或二进制数据将试图插入
- 8. 将字符串数据转换为二进制图像
- 9. PHP将图像文件转换为二进制字符串
- 10. 保存图片或文件的URL
- 11. 写的字符串二进制数据的二进制文件
- 12. 保存数组和字符串到二进制文件在Python
- 13. 在数据库中存储用户的配置文件图片:小图像,因此在数据库中?
- 14. 保存图像的URL数据库表
- 15. 字符集保存二进制数据
- 16. 在数据库中存储和索引二进制字符串
- 17. 在数据库中存储配置文件特定的图像
- 18. 将二进制数据作为字符串存储在Web Sql数据库中
- 19. 将图像保存到照片库并获取保存的图像的URL
- 20. 将在Linq中截断字符串或二进制数据
- 21. 将图片保存在MySQL数据库中并将其保存为文件
- 22. 将图像和文字一起保存在Android数据库中
- 23. 写二进制字符串转换为图像文件
- 24. 从外部URL以二进制形式在数据库中存储图像
- 25. 保存图像文件SQL数据库
- 26. 将二进制文件保存到数据库
- 27. 将用户配置文件映像保存到数据库中
- 28. 将时间序列数据存储在数据库或二进制文件中
- 29. 将matplotlib图形保存为数据库中的图像字段
- 30. 如何使用C1Upload将二进制图像保存到SQL数据库?