HOW TO WRITE THE DATABASE THE RECORDS ON TO THE TEXT FILE
Please find the below code to wite the database record on to the text File
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.PreparedStatement;
/**
*
* @author Aravind
*/
public class Test {
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con; con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","system");
String selectTableSQL = "SELECT *from employees";
Statement statement =con.createStatement();
PreparedStatement ps=null;
String updateQuery="";
ResultSet rs = statement.executeQuery(selectTableSQL);
File f = new File("TransactionDetails");
DateFormat df = new SimpleDateFormat("dd.MM.yy_HH.mm.ss");
Date dateobj = new Date();
String date=(df.format(dateobj)).toString();
String fileName="TransactionDetails/emp"+date+".txt";
f.mkdir();
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
StringBuilder details = new StringBuilder();
details.append(System.getProperty("line.separator"));
while (rs.next()) {
details.append(rs.getString("empID") + " " + rs.getString("empName") + " "
+rs.getString("empSalary"));
details.append(System.getProperty("line.separator"));
}
bw.write(details.toString());
bw.flush();
System.out.println("Success");
}
catch(Exception e){
System.out.println(e);
}
}
}
Goodness, thank you for this extremely point by point article. It gives a considerable measure of data and is exceptionally useful. Keep doing awesome. I adore your articles!
ReplyDeleteDigital Signature Certificate in Gurgaon
ReplyDeleteThanks for sharing this great information I am impressed by the information that you have on this blog. Same as your blog i found another one Oracle Fusion Financials . Actually, I was looking for the same information on internet for
Oracle Fusion Manufacturing and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject, you can learn more about Oracle Fusion Supply Chain Management Cloud .