Click here to Skip to main content
15,880,037 members
Home / Discussions / Java
   

Java

 
Questionhow to write the console output to text file? Pin
Member 1142765718-Aug-16 0:29
Member 1142765718-Aug-16 0:29 
AnswerRe: how to write the console output to text file? Pin
Richard MacCutchan18-Aug-16 0:36
mveRichard MacCutchan18-Aug-16 0:36 
Generalhow to print the fullstr string to a text file. Pin
Member 1142765716-Aug-16 0:39
Member 1142765716-Aug-16 0:39 
GeneralRe: how to print the fullstr string to a text file. Pin
Member 1142765716-Aug-16 0:44
Member 1142765716-Aug-16 0:44 
GeneralRe: how to print the fullstr string to a text file. Pin
Richard MacCutchan16-Aug-16 1:22
mveRichard MacCutchan16-Aug-16 1:22 
SuggestionRe: how to print the fullstr string to a text file. Pin
Richard Deeming16-Aug-16 2:10
mveRichard Deeming16-Aug-16 2:10 
GeneralRe: how to print the fullstr string to a text file. Pin
Richard MacCutchan16-Aug-16 2:58
mveRichard MacCutchan16-Aug-16 2:58 
Questionneed to print the fullstr string to a textfile Pin
Member 1142765716-Aug-16 0:31
Member 1142765716-Aug-16 0:31 
<pre lang="C#">public class sampl{
private static final boolean Null = false;
static String store = null;
static String ip = null;
static String port= null;
static String username = null;
static String password = null;
static String sid = null;
static String get = null;
static String s;
static String v=&quot;success&quot;;
static String sa = null;
static String fullstr = null;
String[] spl= null;
int i = 0;

public static void main(String[] args) throws FileNotFoundException {
{

String csvFile = &quot;C:\\purge_test\\sam.csv&quot;;
BufferedReader br = null;
String line =null;
String cvsSplitBy = &quot;,&quot;;
String[] spl= null;
String detail[]=null;


try {

br = new BufferedReader(new FileReader(csvFile));

// System.out.println(&quot;*****&quot;);

while ( (line = br.readLine() ) != null) {

// System.out.println(&quot;inside&quot;);
// use comma as separator
detail = line.split(cvsSplitBy);

// System.out.println(&quot;server ip = &quot; + detail[1] +&quot;\tport = &quot; + detail[2] + &quot;\tUsername&quot;+ detail[3]+&quot;\tPassword = &quot;+ detail[4]+&quot;\tSID = &quot;+ detail[5]);
try{
store =detail[0];
ip = detail[1];
port= detail[2];
username = detail[3];
password = detail[4];
sid = detail[5];



int po = Integer.parseInt(port);

//step1 load the driver class
Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);

String a = &quot;jdbc:oracle:thin:@&quot;+ip+&quot;:&quot;+po+&quot;:&quot;+sid;
// System.out.println(&quot;string a:&quot; + a);
// System.out.println(&quot;usrname:&quot;+username);
//.out.println(&quot;pswd:&quot;+password);


//step2 create the connection object
Connection con=DriverManager.getConnection(a,username,password);


// Connection con=DriverManager.getConnection(
// &quot;jdbc:oracle:thin:@172.26.64.50:1521:xe&quot;,&quot;OATXPRESS&quot;,&quot;Ckpoatorapw1234&quot;);
//
//
//System.out.println(&quot;qqqq&quot;);

//Connection con=DriverManager.getConnection(&quot;a&quot;,username,password);

//step3 create the statement object
Statement stmt=con.createStatement();

// System.out.println(&quot;rrrr&quot;);

// java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(&quot;dd-MM-yyyy HH:mm:ss&quot;);
//step4 execute query
ResultSet rs=stmt.executeQuery(&quot;select TASK_NAME,to_char(START_TIME,&#39;DD-MON-YYYY HH24:MI:SS&#39;) as RUN_TIME,case when count(*) &gt; 0 then &#39;Task Initiated&#39; else &#39;Task Not Initiated&#39; end as \&quot;TASK_Status\&quot; from TMS_TASK_LOG where (TASK_NAME=&#39;purge_database&#39; or TASK_NAME=&#39;db_stats_collection&#39;) and to_char(START_TIME, &#39;DD-MON-YYYY&#39;)=TO_CHAR(SYSDATE, &#39;DD-MON-YYYY&#39;) group by TASK_NAME,START_TIME &quot;);
//File file = new File(&quot;C:/purge_test/tr.txt&quot;);

// ResultSet rs=stmt.executeQuery(&quot;select TMS_TASK_LOG_ID,TASK_NAME,START_TIME,STATUS from TMS_TASK_LOG where TASK_NAME = &#39;purge_database&#39; AND ROWNUM &lt; = 1 order by 1 desc&quot;);


if(rs.next())
{
System.out.println(rs.getString(1)+&quot; &quot;+rs.getString(2)+&quot; &quot;+rs.getString(3)+&quot; &quot;);

/*System.out.println(rs.getString(1)+&quot; &quot;);
System.out.println(rs.getString(2)+&quot; &quot;);

System.out.println(rs.getString(3)+&quot; &quot;);


//System.out.println(rs.getString(4)+&quot; &quot;);

Date d = new Date();
System.out.println(&quot;date &quot;+d);*/

String fullstr =rs.getString(1)+&quot; &quot;+rs.getString(2)+&quot; &quot;+rs.getString(3)+&quot; &quot;;

System.out.println(&quot;**********&quot;+fullstr);


//__________________________
FileWriter fw = new FileWriter(&quot;C:/purge_test/foooooo.txt&quot;);

for (int i = 0; i &lt; 10; i++) {
fw.write(&quot;something:\t&quot;+ fullstr);
}

fw.close();

System.out.println("****00000******"+fullstr);
}


System.out.println("Done for store :"+store);




//step5 close the connection object
con.close();



}catch(Exception e){ System.out.println(e);}





}



} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

finally {

if (br != null) {
try {

br.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}

}



}}//____________________________________________________</pre>
QuestionDuplicate entry 'VALUE' for key 'PRIMARY' Pin
Django_Untaken13-Aug-16 9:54
Django_Untaken13-Aug-16 9:54 
AnswerRe: Duplicate entry 'VALUE' for key 'PRIMARY' Pin
Patrice T13-Aug-16 16:59
mvePatrice T13-Aug-16 16:59 
GeneralRe: Duplicate entry 'VALUE' for key 'PRIMARY' Pin
Django_Untaken14-Aug-16 3:28
Django_Untaken14-Aug-16 3:28 
GeneralRe: Duplicate entry 'VALUE' for key 'PRIMARY' Pin
Patrice T14-Aug-16 3:39
mvePatrice T14-Aug-16 3:39 
Question[SOLVED] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Pin
Django_Untaken4-Aug-16 8:35
Django_Untaken4-Aug-16 8:35 
AnswerRe: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Pin
Richard MacCutchan4-Aug-16 20:38
mveRichard MacCutchan4-Aug-16 20:38 
QuestionMaven cmd line Tests failing,M aven Test Run Through Eclipse Pass Pin
DLamar123-Aug-16 8:29
DLamar123-Aug-16 8:29 
AnswerRe: Maven cmd line Tests failing,M aven Test Run Through Eclipse Pass Pin
jschell12-Aug-16 10:54
jschell12-Aug-16 10:54 
Questionread and traverse over the TTL file Pin
Eng.Roqaya22-Jul-16 8:12
Eng.Roqaya22-Jul-16 8:12 
AnswerRe: read and traverse over the TTL file Pin
Richard MacCutchan22-Jul-16 21:25
mveRichard MacCutchan22-Jul-16 21:25 
Question.jar to .exe Pin
prateek chauhan19-Jul-16 18:47
prateek chauhan19-Jul-16 18:47 
AnswerRe: .jar to .exe Pin
Richard MacCutchan19-Jul-16 21:48
mveRichard MacCutchan19-Jul-16 21:48 
AnswerRe: .jar to .exe Pin
Afzaal Ahmad Zeeshan22-Jul-16 8:33
professionalAfzaal Ahmad Zeeshan22-Jul-16 8:33 
AnswerRe: .jar to .exe Pin
Curry Francis25-Jul-16 1:50
Curry Francis25-Jul-16 1:50 
GeneralRe: .jar to .exe Pin
Richard MacCutchan25-Jul-16 3:16
mveRichard MacCutchan25-Jul-16 3:16 
GeneralRe: .jar to .exe Pin
Curry Francis27-Jul-16 4:01
Curry Francis27-Jul-16 4:01 
GeneralRe: .jar to .exe Pin
Richard MacCutchan27-Jul-16 4:51
mveRichard MacCutchan27-Jul-16 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.