Share on Google+Share on Google+

Retrieve data from the database and write into ppt file

In this section, you will learn how to retrieve data from the database and write into the .ppt file.

Java Retrieve data from the database & write into ppt file

In this section, we are going to retrieve data from the database and write into the .ppt file. For this purpose, we have used Jakarta POI api to create a .ppt file. The class SlideShow creates a powerpoint documentation. The Slide class represents a slide in a PowerPoint Document which allows to access the text and the layout of the slide. The class TextBox is responsible for the text as well as the properties and methods that control the alignment and anchoring of the text.With the use of setText() method, we have inserted database values into it.

Here is the code:

import java.awt.*;
import java.sql.*;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.model.TextBox;

public class createNewPresentation {
	public static void main(String a[]) {
		try {
			SlideShow slideShow = new SlideShow();
			Slide slide = slideShow.createSlide();
			TextBox txt = new TextBox();
			Slide slide1 = slideShow.createSlide();
			TextBox txt1 = new TextBox();
			Connection con = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/register", "root", "root");
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select * from data");
			String name = "";
			String address = "";
			while ( {
				name += rs.getString("name") + "\n";
				address += rs.getString("address") + "\n";
			txt.setText(name + " ");
			txt1.setText(address + " ");
			FileOutputStream out = new FileOutputStream("data.ppt");
		} catch (Exception e) {


Posted on: October 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null