I am new to database handling. I am creating a karaoke player in Java, where I need to have a database. I don't have to get material (sound and text file) directly from hard disk, but I want a database (SQL Server, Oracle, etc) to store them, so that I can have an object, which can refer/point to them. Is it possible??
我是数据库处理的新手。我正在用Java创建一个卡拉OK播放器,我需要有一个数据库。我不必直接从硬盘获取材料(声音和文本文件),但我想要一个数据库(SQL Server,Oracle等)来存储它们,这样我就可以有一个对象,可以引用/指向他们。可能吗??
public class SoundPlayer extends JComponent
{
String windowName;
Clip clip;Clip clip2;
public static void main(String[] args) throws UnsupportedAudioFileException,
IOException, LineUnavailableException, InterruptedException
{
JFrame f=new JFrame("hh");
f.getContentPane();
f.pack();
f.setVisible(true);
}
private String String;
public SoundPlayer(File file) throws UnsupportedAudioFileException, IOException, LineUnavailableException, InterruptedException {
AudioInputStream ain=AudioSystem.getAudioInputStream(file);
try
{
DataLine.Info info=new DataLine.Info(Clip.class,ain.getFormat());
AudioFormat inFormat = ain.getFormat();
clip=(Clip) AudioSystem.getLine(info);
//rest code
The object should be available in my program, so that I can access it.
该对象应该在我的程序中可用,以便我可以访问它。
2 个解决方案
#1
2
Yes, it's possible (look at BLOB support in Oracle and JDBC), but the generally accepted way to do this is to store the files in the file system, and then just store the path to the file in the database.
是的,这是可能的(查看Oracle和JDBC中的BLOB支持),但普遍接受的方法是将文件存储在文件系统中,然后将文件路径存储在数据库中。
As it looks like you're writing a desktop application, you have to think about how to access this information. If this is a single-user application with a local database, then you'll be fine with files in the local file system and paths in the database.
由于您正在编写桌面应用程序,因此必须考虑如何访问此信息。如果这是具有本地数据库的单用户应用程序,那么您可以使用本地文件系统中的文件和数据库中的路径。
If this is a multi-user system with a shared database, then you'll probably want to create a server that handles requests from the desktop app. It can look up the path in the database, get the file, and return it to the desktop app.
如果这是一个具有共享数据库的多用户系统,那么您可能希望创建一个处理桌面应用程序请求的服务器。它可以在数据库中查找路径,获取文件,然后将其返回到桌面应用程序。
#2
2
Sure you can!
你当然可以!
You can store any kind of value in a database, even raw binary data from your phisical files.
您可以在数据库中存储任何类型的值,甚至是来自您的物理文件的原始二进制数据。
You might create entities like these (just a sample in T-SQL):
您可以创建这样的实体(只是T-SQL中的一个示例):
CREATE TABLE Singer{
ID int primary key,
Name varchar(50),
}
CREATE TABLE Songs{
ID int primary key,
IDSinger int references Singer(ID),
Title varchar(50),
Content varbinary(max) --here goes the raw binary of your file
}
#1
2
Yes, it's possible (look at BLOB support in Oracle and JDBC), but the generally accepted way to do this is to store the files in the file system, and then just store the path to the file in the database.
是的,这是可能的(查看Oracle和JDBC中的BLOB支持),但普遍接受的方法是将文件存储在文件系统中,然后将文件路径存储在数据库中。
As it looks like you're writing a desktop application, you have to think about how to access this information. If this is a single-user application with a local database, then you'll be fine with files in the local file system and paths in the database.
由于您正在编写桌面应用程序,因此必须考虑如何访问此信息。如果这是具有本地数据库的单用户应用程序,那么您可以使用本地文件系统中的文件和数据库中的路径。
If this is a multi-user system with a shared database, then you'll probably want to create a server that handles requests from the desktop app. It can look up the path in the database, get the file, and return it to the desktop app.
如果这是一个具有共享数据库的多用户系统,那么您可能希望创建一个处理桌面应用程序请求的服务器。它可以在数据库中查找路径,获取文件,然后将其返回到桌面应用程序。
#2
2
Sure you can!
你当然可以!
You can store any kind of value in a database, even raw binary data from your phisical files.
您可以在数据库中存储任何类型的值,甚至是来自您的物理文件的原始二进制数据。
You might create entities like these (just a sample in T-SQL):
您可以创建这样的实体(只是T-SQL中的一个示例):
CREATE TABLE Singer{
ID int primary key,
Name varchar(50),
}
CREATE TABLE Songs{
ID int primary key,
IDSinger int references Singer(ID),
Title varchar(50),
Content varbinary(max) --here goes the raw binary of your file
}