Retrieving blob values from database in string format Java Program

import java.sql.*;

public class DemoBlob
{
public static void main(String args[])throws Exception
{

Class.forName("com.mysql.jdbc.Driver");  //type 4 driver
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root","rat");//connection
System.out.println("Connection successful:"+con);
 PreparedStatement ps=con.prepareStatement("select * from login");
 ResultSet res=ps.executeQuery();
 res.next();

        Blob b= res.getBlob(1);
        long len=b.length();
       
        byte value[]=b.getBytes(1, (int)(len));
        String str=new String(value);
        System.out.println(str);
}
}

A Simple Java Program to Insert Value in DataBase

import java.util.Date;
import java.sql.*;

public class DemoDate
{
public static void main(String args[])throws Exception
{
Date d=new Date();
long l=d.getTime();
System.out.println(l);
java.sql.Date obj=new java.sql.Date(l);
Class.forName("com.mysql.jdbc.Driver");  //type 4 driver
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root","rat");//connection
System.out.println("Connection successful:"+con);
 PreparedStatement ps=con.prepareStatement("insert into demo values(?)");
 ps.setDate(1, obj);
 ps.executeUpdate();
 System.out.println("operation successful");


 ps=con.prepareStatement("select * from demo");
 ResultSet res=ps.executeQuery();
 res.next();
 d=res.getDate(1);
 System.out.println(d);
}
}

Create A Media Player in Java Or Play Files

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.media.*;

public class MediaPlayerDemo extends JFrame
{
private Player player;
private File file;

public MediaPlayerDemo()
{
super( "Java Media Player" );

JButton openFile = new JButton( "Open file (Browse) to play" );
openFile.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
openFile();
createPlayer();
}
});
getContentPane().add( openFile, BorderLayout.NORTH );

setSize( 100, 200 );
show();
}

private void openFile()
{
JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog( this );

if ( result == JFileChooser.CANCEL_OPTION )
file = null;
else
file = fileChooser.getSelectedFile();
}

private void createPlayer()
{
if ( file == null )
return;

removePreviousPlayer();

try
{
player = Manager.createPlayer( file.toURL() );
player.addControllerListener( new EventHandler() );
player.start();
}
catch ( Exception e )
{
JOptionPane.showMessageDialog( this, "Invalid file or location", "Error loading file",
JOptionPane.ERROR_MESSAGE );
}
}

private void removePreviousPlayer()
{
if ( player == null )
return;

player.close();

Component visual = player.getVisualComponent();
Component control = player.getControlPanelComponent();

Container c = getContentPane();

if ( visual != null )
c.remove( visual );

if ( control != null )
c.remove( control );
}

public static void main(String args[])
{
MediaPlayerDemo app = new MediaPlayerDemo();

app.addWindowListener( new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
System.exit(0);
}
}
}

private class EventHandler implements ControllerListener
{
public void controllerUpdate( ControllerEvent e )
{
if ( e instanceof RealizeCompleteEvent )
{
Container c = getContentPane();

Component visualComponent = player.getVisualComponent();

if ( visualComponent != null )
c.add( visualComponent, BorderLayout.CENTER );

Component controlsComponent = player.getControlPanelComponent();

if ( controlsComponent != null )
c.add( controlsComponent, BorderLayout.SOUTH );

c.doLayout();
}
}
}
}

A simple Audio File Load and Play Java Program

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoadAudioAndPlay extends JApplet
{
private AudioClip sound1, sound2, currentSound;
private JButton playSound, loopSound, stopSound;
private JComboBox chooseSound;

public void init()
{
Container c = getContentPane();
c.setLayout( new FlowLayout() );

String choices[] = { "Welcome", "Hi" };
chooseSound = new JComboBox( choices );
chooseSound.addItemListener( new ItemListener()
{
public void itemStateChanged( ItemEvent e )
{
currentSound.stop();

currentSound = chooseSound.getSelectedIndex() == 0 ? sound1 : sound2;
}
});
c.add( chooseSound );

ButtonHandler handler = new ButtonHandler();
playSound = new JButton( "Play" );
playSound.addActionListener( handler );
c.add( playSound );
loopSound = new JButton( "Loop" );
loopSound.addActionListener( handler );
c.add( loopSound );
stopSound = new JButton( "Stop" );
stopSound.addActionListener( handler );
c.add( stopSound );

sound1 = getAudioClip( getDocumentBase(), "welcome.wav" );
sound2 = getAudioClip( getDocumentBase(), "hi.au" );
currentSound = sound1;
}

public void stop()
{
currentSound.stop();
}

private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
if ( e.getSource() == playSound )
currentSound.play();
else if ( e.getSource() == loopSound )
currentSound.loop();
else if ( e.getSource() == stopSound )
currentSound.stop();
}
}
}

World Trade Park

Rajasthan's Largest Building WTP


Chairmen - Mr.Anoop Bartaria

  • 5 Star Hotels
  • 5 Screen Multiplex
  • Food Court
  • Mini Golf Course
  • 250 Showroom or more
  • Wireless Lan
  • IT Friendly Enviornment
  • Under Water Restaurent 

JDBC (Java DataBase Connectivity Program) at RAT Jaipur

                                     JDBC (Java DataBase Connectivity Program)

Java Assignment for IT & CS 6 sem,,, secsikar

                                                 Click Here to DOWNLOAD