Solved

reading output from console to file

Posted on 2002-05-06
8
231 Views
Last Modified: 2008-02-01
hai everybody,
               By using swings i connected to database.
ex:
userid aaaaaa
password xxxxx

i created some buttons insert update view
when i click insert userid and passowrd will insert into database.

If i click the view button the o/p will come from database and it prints into the console.Instead of printing on console i want to store that into anyfile.

reply as early
cheers
0
Comment
Question by:indupriya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:sanjay_thakur
ID: 6992801
0
 

Author Comment

by:indupriya
ID: 7002976
hai evrybody,
                here i am sending my code. my aim is to send the o/p into one file when i click VIEW button.By using this code i can display the o/p in the console.Because i used System.out.println("------"),Instead of that i want to send the o/p into one file,i didn't get how to use files, can anybody can help

reply asap
bye




import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DateFormat;

public class grapescust extends JFrame implements ActionListener
{
JButton INSERT,UPDATE,DELETE,VIEW,CLEAR;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
JTextArea ta;

//int uid;
Connection con;
Statement st1,st2;
ResultSet rs1;
Container c;
//int currentrec=0;
grapescust()
{
c=getContentPane();
l1=new JLabel("customer Number");
l2=new JLabel("customer Name");
l3=new JLabel("House Number");
l4=new JLabel("Street");
l5=new JLabel("Area");
l6=new JLabel("County");
l7=new JLabel("City");
l8=new JLabel("Post Code");
l9=new JLabel("Phone Number");
l10=new JLabel("Remarks");

INSERT=new JButton("INSERT");
UPDATE=new JButton("UPDATE");
DELETE=new JButton("DELETE");
VIEW=new JButton("VIEW");
CLEAR=new JButton("CLEAR");

t1=new JTextField("",20);
t2=new JTextField("",20);
t3=new JTextField("",20);
t4=new JTextField("",20);
t5=new JTextField("",20);
t6=new JTextField("",20);
t7=new JTextField("",20);
t8=new JTextField("",20);
t9=new JTextField("",20);
t10=new JTextField("",20);
ta=new JTextArea("",200,200);
INSERT.addActionListener(this);
UPDATE.addActionListener(this);
DELETE.addActionListener(this);
VIEW.addActionListener(this);
CLEAR.addActionListener(this);
setTitle("Grapes Restaurant Customer DETAILS");
setSize(550,450);
Color cc=new Color(200,120,150);
setBackground(cc);
c.setLayout(null);
l1.setBounds(50,50,100,20);
l2.setBounds(50,75,100,20);
l3.setBounds(50,100,100,20);
l4.setBounds(50,125,100,20);
l5.setBounds(50,150,100,20);
l6.setBounds(50,175,100,20);
l7.setBounds(50,200,100,20);
l8.setBounds(50,225,100,20);
l9.setBounds(50,250,100,20);
l10.setBounds(50,275,100,20);

t1.setBounds(150,50,100,20);
t2.setBounds(150,75,100,20);
t3.setBounds(150,100,100,20);
t4.setBounds(150,125,100,20);
t5.setBounds(150,150,100,20);
t6.setBounds(150,175,100,20);
t7.setBounds(150,200,100,20);
t8.setBounds(150,225,100,20);
t9.setBounds(150,250,100,20);
t10.setBounds(150,275,100,20);

INSERT.setBounds(400,50,70,25);
UPDATE.setBounds(400,100,70,25);
DELETE.setBounds(400,150,70,25);
VIEW.setBounds(400,175,70,25);
CLEAR.setBounds(400,200,70,25);
ta.setBounds(300,250,400,400);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(l4);
c.add(l5);
c.add(l6);
c.add(l7);
c.add(l8);
c.add(l9);
c.add(l10);

c.add(t1);
c.add(t2);
c.add(t3);
c.add(t4);
c.add(t5);
c.add(t6);
c.add(t7);
c.add(t8);
c.add(t9);
c.add(t10);

c.add(INSERT);
c.add(UPDATE);
c.add(DELETE);
c.add(VIEW);
c.add(CLEAR);
c.add(ta);
setVisible(true);
System.out.println("welcome");
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:prasad2","scott","tiger");
System.out.println("Connection Established");
st1=con.createStatement();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}//end of constructor

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(INSERT))
{
          try
              {

int cno=Integer.parseInt(t1.getText());
String cname=t2.getText();
int hno=Integer.parseInt(t3.getText());
String street=t4.getText();
String area=t5.getText();
String county=t6.getText();
String city=t7.getText();
String pcode=t8.getText();
String pno=t9.getText();
String remarks=t10.getText();

System.out.println("welcome in insert");
int x=st1.executeUpdate("insert into grapescust values("+cno+",'"+cname+"',"+hno+",'"+street+"','"+area+"','"+county+"','"+city+"','"+pcode+"','"+pno+"','"+remarks+"')");
System.out.println("welcome after insert");
ta.setText("one row  has been inserted");
              }
 catch(Exception e)
 {
ta.setText("");
ta.setText(e.getMessage());
try
{
con.rollback();
}
catch(Exception ee)
{
System.out.println(ee);
}
}
}

if(ae.getSource().equals(UPDATE))
{
try
{

int eno=Integer.parseInt(t1.getText());
String ename=t2.getText();
String sname=t3.getText();
String fname=t4.getText();
String dob=t5.getText();
int age=Integer.parseInt(t6.getText());
int hno=Integer.parseInt(t7.getText());
String street=t8.getText();
String area=t9.getText();
String county=t10.getText();
String city=t11.getText();
String pcode=t12.getText();
//double pno=Double.parseDouble(t13.getText());
String pno=t13.getText();
String doj=t14.getText();
String wstatus=t15.getText();
int thours=Integer.parseInt(t16.getText());
int hpay=Integer.parseInt(t17.getText());
int wages=Integer.parseInt(t18.getText());
String estatus=t19.getText();
String remarks=t20.getText();



int amount1=Integer.parseInt(t3.getText());
int updat=st1.executeUpdate("update grapesemployee set empname='"+ename+"',surname='"+sname+"',forename='"+fname+"',dob='"+dob+"',age="+age+",houseno="+hno+",street='"+street+"',area='"+area+"',county='"+county+"',city='"+city+"',postcode='"+pcode+"',phoneno='"+pno+"',doj='"+doj+"',workstatus='"+wstatus+"',totalhours="+thours+",holidaypay="+hpay+",wages="+wages+",empstatus='"+estatus+"',remarks='"+remarks+"'
where empno="+eno+"");
ta.setText(updat+" rows has been updated");
}
catch(SQLException e)
{
ta.setText(e.getMessage());
}
 }

if(ae.getSource().equals(DELETE))
{
try
{

int eno=Integer.parseInt(t1.getText());
String ename=t2.getText();
String sname=t3.getText();
String fname=t4.getText();
String dob=t5.getText();
int age=Integer.parseInt(t6.getText());
int hno=Integer.parseInt(t7.getText());
String street=t8.getText();
String area=t9.getText();
String county=t10.getText();
String city=t11.getText();
String pcode=t12.getText();
//double pno=Double.parseDouble(t13.getText());
String pno=t13.getText();
String doj=t14.getText();
String wstatus=t15.getText();
int thours=Integer.parseInt(t16.getText());
int hpay=Integer.parseInt(t17.getText());
int wages=Integer.parseInt(t18.getText());
String estatus=t19.getText();
String remarks=t20.getText();
int del=st1.executeUpdate("delete from  grapesemployee where empno="+eno);
ta.setText(del+" rows has been deleted");
}
catch(SQLException e)
{
ta.setText(e.getMessage());
}
 }
if(ae.getSource().equals(VIEW))
{
try
{
rs1=st1.executeQuery("select * from grapesemployee");
System.out.println("Empno"+"\t\t"+"Empname"+"\t\t"+"surname");
System.out.println("----------------------------------------");

while(rs1.next())
{
System.out.println(rs1.getString(1)+"\t\t"+rs1.getString(2)+"\t\t"+rs1.getString(3));
}
}
catch(Exception e)
{
System.out.println(e);
}
}
if(ae.getSource().equals(CLEAR))
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");
t9.setText("");
t10.setText("");
t11.setText("");
t12.setText("");
t13.setText("");
t14.setText("");
t15.setText("");
t16.setText("");
t17.setText("");
t18.setText("");
t19.setText("");
t20.setText("");

ta.setText("");
}

}
public static void main(String args[])
{
JFrame is=new grapescust();

}

}


when i click view button it displays the o/p on the console, Instead of printing o/p on console i want
to send the o/p into one file,can anyone can help me.
I want to print the o/p in the p.c only.
reply asap
bye
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:indupriya
ID: 7006764
hai every body,
                    Any experts is there to solve my query, waiting for response.

cheers
0
 

Author Comment

by:indupriya
ID: 7011429
hai every body,
                    did anyone is can help, how to store the o/p into files .Actually when i click view button it displays the o/p on console, but i want to send the o/p to file.reply
bye
0
 

Author Comment

by:indupriya
ID: 7011430
hai every body,
                    did anyone is can help, how to store the o/p into files .Actually when i click view button it displays the o/p on console, but i want to send the o/p to file.reply
bye
0
 
LVL 35

Expert Comment

by:girionis
ID: 8709805
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- To be PAQ'ed and points refunded

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 8774350
Per Recommendation,

PashaMod
Community Support Moderator @Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question