Question

Locked

I nee to get data from database table and i want to store it in file

By kh.ramana ·
hi all,

I nee dto store data from database table and i want to store it in file.can any one help me..

sample code----------i have executed this code but it is give some unnecessary symbels in middle...and data is not going to next line....can any one check this and send me the modified code..................


------
import java.io.FileOutputStream;
import java.io.StringReader;
import java.sql.*;

class JdbcEx2
{
public static void main(String as[])
{
try{


Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/b14db","root","ramana");
Statement st=con.createStatement();

//String sql="insert into b14student values('"+sid+"','"+sname+"','"+email+"','"+phone+"')";
String sql="select * from b14student";
FileOutputStream fos=new FileOutputStream("sd1.xls");
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
int sid=rs.getInt(1);
String sname=rs.getString(2);
String email=rs.getString(3);
long phone=rs.getLong(4);
String s="\b"+String.valueOf(sid)+"\t"+sname+"\t"+email+"\t"+String.valueOf(phone)+"\t";
try{
//BufferedInputStream bis=new BufferedInputStream(System.in);

StringReader sr=new StringReader(s);


int x=0;
do{
x=sr.read();

fos.write(x);

//System.out.println();
}while(x!=-1);

}catch(Exception e)
{}

}

//boolean execute()
//Resultset
//System.out.println(x);
}catch(Exception e)
{
e.printStackTrace();
}
}
}

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Windows Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums