Solved

reading output from console to file

Posted on 2002-05-06
8
229 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
 
LVL 4

Expert Comment

by:sanjay_thakur
ID: 6992802
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
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!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to install java on RHEL image on EC2 4 56
Android development question 2 78
servlet and mdb, jms error 1 57
activeMQ Queue Messages Enqueued and Messages Dequeued 1 32
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

756 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