-1

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??

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.

NullUserException
  • 83,810
  • 28
  • 209
  • 234
joey rohan
  • 3,505
  • 5
  • 33
  • 70
  • Yes you can. Blob types are for that purpose. Your data will be stored as byte array I guess. – kosa Nov 14 '12 at 16:27
  • create some tables. one of these will have a BLOB type column in it. this will contain the data for what would otherwise be a file. – Randy Nov 14 '12 at 16:27
  • @Nambari,randy can u guys expand pls?i am new to this..from where i can start n stuff – joey rohan Nov 14 '12 at 16:29
  • I woluln't recommend that. I'd store all files (audio) directly into the file system and only store file path in the database (and other info). You can read this two threads: http://stackoverflow.com/a/585235/1782913 http://stackoverflow.com/a/1234707/1782913 – fabricio Nov 14 '12 at 16:33
  • possible duplicate of [User images - database vs. filesystem storage](http://stackoverflow.com/questions/585224/user-images-database-vs-filesystem-storage) – APC Jan 11 '13 at 21:35

2 Answers2

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.

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.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
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):

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
}
LittleSweetSeas
  • 6,786
  • 2
  • 21
  • 26