Convert sqlserver database to msexcel

Convert sqlserver database to msexcel

How to i convert sqlserver database values into msexcel sheet using java...

View Answers

March 29, 2012 at 1:08 PM

We have used MySQL database.

import java.io.*;
import java.sql.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class ExcelFile {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test", "root", "root");
            PreparedStatement psmnt = null;
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("Select * from student");

            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("Excel Sheet");
            HSSFRow rowhead = sheet.createRow((short) 0);
            rowhead.createCell((short) 0).setCellValue("Roll No");
            rowhead.createCell((short) 1).setCellValue("Name");
            rowhead.createCell((short) 2).setCellValue("Class");
            rowhead.createCell((short) 3).setCellValue("Marks");
            rowhead.createCell((short) 4).setCellValue("Grade");

            int index = 1;
            while (rs.next()) {

                HSSFRow row = sheet.createRow((short) index);
                row.createCell((short) 0).setCellValue(rs.getInt(1));
                row.createCell((short) 1).setCellValue(rs.getString(2));
                row.createCell((short) 2).setCellValue(rs.getString(3));
                row.createCell((short) 3).setCellValue(rs.getInt(4));
                row.createCell((short) 4).setCellValue(rs.getString(5));
                index++;
            }
            FileOutputStream fileOut = new FileOutputStream("c:\\excelFile.xls");
            wb.write(fileOut);
            fileOut.close();
            System.out.println("Data is saved in excel file.");
            rs.close();
            connection.close();
        } catch (Exception e) {
        }
    }
}

You need POI API to run the above code.









Related Tutorials/Questions & Answers:
Convert sqlserver database to msexcel
Convert sqlserver database to msexcel  How to i convert sqlserver database values into msexcel sheet using java...   We have used MySQL database. import java.io.*; import java.sql.*; import
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C
Advertisements
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C#. <?xml version="1.0" ?> <!DOCTYPE PubmedArticleSet (View Source
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
ms sqlserver
ms sqlserver  hii, i m getting trouble in restoring a database file in MS SQLServer 2000 . all i have is signature.bkp , query.sql, signaturebackup.bkp files... please guide me how i restore these backup files in new database
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet code  Hi sir, I would like to know how to send the form data from html page to database by calling servlet code from html page .   
Fetch Records from SQL database and convert into XML file
Fetch Records from SQL database and convert into XML file  Hi Experts... it means stating that it will lock the view while accessing the database so... that it will lock the view while accessing the database so that new records will not get
jsp with sqlserver - JDBC
and retrive images in sqlserver from jsp program. can anybody suggest me the code for that.Actually my need s to store lot and lot of images in database.  Hi friend, Insert image code   retrive image from database
ModuleNotFoundError: No module named 'dbt-sqlserver'
ModuleNotFoundError: No module named 'dbt-sqlserver'  Hi, My... 'dbt-sqlserver' How to remove the ModuleNotFoundError: No module named 'dbt-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'easy-sqlserver'
ModuleNotFoundError: No module named 'easy-sqlserver'  Hi, My... named 'easy-sqlserver' How to remove the ModuleNotFoundError: No module named 'easy-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'magical-sqlserver'
ModuleNotFoundError: No module named 'magical-sqlserver'  Hi, My... named 'magical-sqlserver' How to remove the ModuleNotFoundError: No module named 'magical-sqlserver' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'dbt-sqlserver'
ModuleNotFoundError: No module named 'dbt-sqlserver'  Hi, My... 'dbt-sqlserver' How to remove the ModuleNotFoundError: No module named 'dbt-sqlserver' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-sqlserver'
ModuleNotFoundError: No module named 'django-sqlserver'  Hi, My... named 'django-sqlserver' How to remove the ModuleNotFoundError: No module named 'django-sqlserver' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'easy-sqlserver'
ModuleNotFoundError: No module named 'easy-sqlserver'  Hi, My... named 'easy-sqlserver' How to remove the ModuleNotFoundError: No module named 'easy-sqlserver' error? Thanks   Hi, In your python
database
database  database
database
database  database application
Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF
Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF  We are facing quite a issue with having track changes & comments in our documents(word/Excel). We have 3 requirement
Database backup
Database backup  I am developing c# application in which i am using Microsoft Access database (OLEdb connections). I want to take backup of database programaticaly. Or as i can tae it in sqlserver 2008 r2(.bak) file. How can i
database
database  the code for initializing the database connection
database
database  i want to let the user select the name of database and then delete that database.......im doing project in swings netbeans
Maven Repository/Dependency: org.n52.sensorweb.sos | hibernate-datasource-sqlserver
hibernate-datasource-sqlserver. Latest version of org.n52.sensorweb.sos:hibernate-datasource-sqlserver dependencies. # Version... in Eclipse? Maven 3 Tutorial Convert Maven project to Eclipse Web Project
database
database  use of hyperlink to show the data from database
database
database  i need to insert time in my database. i need a code to insert time in my database. its very urgent
us.fatehi - schemacrawler-sqlserver version 14.16.02 Maven dependency. How to use schemacrawler-sqlserver version 14.16.02 in pom.xml?
us.fatehi  - Version 14.16.02 of schemacrawler-sqlserver Maven dependency...-sqlserver in pom.xml? How to use schemacrawler-sqlserver version 14.16.02 in pom.xml... us.fatehi  - Version 14.16.02 of schemacrawler-sqlserver in project by the help
us.fatehi - schemacrawler-sqlserver version 16.2.2 Maven dependency. How to use schemacrawler-sqlserver version 16.2.2 in pom.xml?
us.fatehi  - Version 16.2.2 of schemacrawler-sqlserver Maven dependency? How to use  us.fatehi  - Version 16.2.2 of schemacrawler-sqlserver in pom.xml? How to use schemacrawler-sqlserver version 16.2.2 in pom.xml? Learn
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  im doing my project in netbeans swings...wn a user wants to create a database from the gui...i want to display an error msg if a database with that name already exists and if it does not exist new database should
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
database
database  tell me use about database and give me a small program.   It is secure and can easily be accessed, managed, and updated. Moreover... links: Connect JSP with database Mysql Connect Java with database Mysql
Regarding connection between sqlserver 2005 and android application
Regarding connection between sqlserver 2005 and android application  hi to all, i want to know how to create webservice to connect sqlserver 2005 and android. can you please help me by providing source code for ref.. thanks
database
database  I wanted to know if it is possible to create a database in mysql by letting the user enter the name of the database in swing gui..im doing my project in netbeans...Thank You
database
database  I wanted to know if it is possible to establish database connection on a remote pc with mysql using java swings from netbeans and then create a database on the remote pc.... Kindly help me
DATABASE
DATABASE  How can i get combo box values from database?? or how can i get values in the drop down menu of the html which is similar to dat of combo box in java - from database
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing
Database
Database  I am working in jsf2.Fro a demo i created database in ms access.no wi want to retrive a record from database for a particular data.I need help as I am stuck
Database
Database  from java code i have to retrieve some data from a database, which is present in a different timezone. Scenario :- My database... in database timezone is 9PM 15APR2012. I want to retrieve something from database
DATABASE
DATABASE  I can't send different information from different form into a single table in my database
Database
Database  Can i get a code for database connectivity Myeclipse 3.3 to MySql manager 2005
database
database  dateofbirth is not save into the database while i am enter from html browser.it shows as null.whats the reason
database
database  sir.. how we can uplaod the database in the data file(ms access)please send me a solution
database
database  how we ca upload the data in the database file(ms access
database
database  hi i want to develop one patient database can any one provide me the guide
database
database  In my project where u helped me to display the databases present im mysql database on the Jlist and then the respective tables in that database on another jlist and then the column names on another jlist I dont want
database
database  In my project,i want the user to specify the name of the database he wants to create in mysql and then also the name of the table along with the column names he wants in that database....Im doing my project in netbeans
database
database  Im doing my project in java swings...netbeans I wanted java source code to establish connection to postgresql_8.1 using jdbc and create a user defined database and a table in that database and insert values Plz help me
database
database  Can you please help me to establish database connection to ms sql 2000 from java swing in netbeans
database
database  i need optimised searching algorithm to retrieve the data from the database and optimised ranking algorithm to display the reults into the user
database
the names of the databases present in mysql database on a Jlist that is already present on the gui and when the user selects a particular database,the tables present under that database should be displayed on another Jlist which is present
database
database  I want to let the user select one of the database type... give the name of the database name that he want to create in a textfield... database..im doing my project in java swings.....netbeans Kindly help me ThankYou
database
database  I wanted to know if it is possible to take the fields of a table from a user and then create a table in mysql database......im doing my project in swings netbeans Plz help me ThankYou

Ads