Solved

reading output from console to file

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

Expert Comment

by:sanjay_thakur
Comment Utility
0
 
LVL 4

Expert Comment

by:sanjay_thakur
Comment Utility
0
 

Author Comment

by:indupriya
Comment Utility
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
 

Author Comment

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

cheers
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:indupriya
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Per Recommendation,

PashaMod
Community Support Moderator @Experts Exchange
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now