Monday, August 27, 2007

JDBC Program to write to a Excel File

public class JdbcConnect {
public static void main(String args[]){
try{
Statement st = null;
ResultSet rs = null;
String sql = "select * from tab";
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
System.out.println(" Driver Loaded"); //"jdbc:oracle:thin:@//localhost:1521/XE
DriverManager.getConnection("jdbc:db2://localhost:6789/database","ganesh","ganesh");

System.out.println("Connection Created ");

st = connection.createStatement();
rs = st.executeQuery("select username from ganesh.sample");
System.out.println("LEN:: "+rs.getFetchSize());
StringBuffer sBuffer = new StringBuffer();
while(rs.next()){
sBuffer.append(rs.getString(1));
sBuffer.append("\n");

}

BufferedWriter bw = new BufferedWriter(new FileWriter("test1.xls"));
bw.write("new file excel \n \n "+sBuffer.toString());
bw.close();


}catch(Exception exp){
exp.printStackTrace();
}
}
}

Sunday, August 26, 2007

Free Online Programming Books



FreeTechBooks.com lists free online computer science, engineering and programming books, textbooks and lecture notes, all of which are legally and freely available over the Internet. All the books listed in this site are hosted on websites that belong to the authors or the publishers. We are allowed to view, download and with a very few exceptions, print the books for our own private use at no charge more>>