Hai to all,,
i had to tried to retrive and write a single row to a file from the database..
But dont know to write all the retrived rows to a file from the database..
how to do that...
here are my codings for writing a single row to a file... - import java.io.*;
-
import java.sql.*;
-
-
public class DataBase {
-
-
public static void main(String args[]) {
-
String Driver;
-
Statement stmt;
-
ResultSet rs;
-
-
Driver = "com.mysql.jdbc.Driver";
-
Connection con = null;
-
try {
-
File file = new File("C:/test.txt");
-
BufferedWriter out = new BufferedWriter(new FileWriter(file));
-
Class.forName(Driver);
-
con = DriverManager.getConnection("jdbc:mysql://192.168.0.01/senthil","root","");
-
if(!con.isCloses)
-
{
-
System.out.println("Successfully connected to MySQL DataBase \n");
-
stmt = con.createStatement();
-
rs = stmt.executeQuery("SELECT * FROM employees");
-
InputStream data= null;
-
System.out.println("Display all results: ");
-
while (rs.next()) {
-
int id = rs.getInt("Employee_Number");
-
String name = rs.getString("First_Name");
-
String addr = rs.getString("Second_Name");
-
data = rs.getBinaryStream(1);
-
int temp=0;
-
while( (temp = data.read()) != -1) {
-
out.write(temp); }
-
System.out.println( id + name + addr);
-
}
-
-
out.flush();
-
out.close();
-
-
}
-
-
} catch(Exception e) {
-
System.err.println("Exception: " + e.getMessage());
-
} finally {
-
try {
-
if(con != null)
-
con.close();
-
} catch(SQLException e) {}
-
}
-
}
-
}
Can any one plzz help me soon...
thanks and regards..
senthil
9 2829
Hai to all,,
i had to tried to retrive and write a single row to a file from the database..
But dont know to write all the retrived rows to a file from the database..
how to do that...
here are my codings for writing a single row to a file... - import java.io.*;
-
import java.sql.*;
-
-
public class DataBase {
-
-
public static void main(String args[]) {
-
String Driver;
-
Statement stmt;
-
ResultSet rs;
-
-
Driver = "com.mysql.jdbc.Driver";
-
Connection con = null;
-
try {
-
File file = new File("C:/test.txt");
-
BufferedWriter out = new BufferedWriter(new FileWriter(file));
-
Class.forName(Driver);
-
con = DriverManager.getConnection("jdbc:mysql://192.168.0.01/senthil","root","");
-
if(!con.isCloses)
-
{
-
System.out.println("Successfully connected to MySQL DataBase \n");
-
stmt = con.createStatement();
-
rs = stmt.executeQuery("SELECT * FROM employees");
-
InputStream data= null;
-
System.out.println("Display all results: ");
-
while (rs.next()) {
-
int id = rs.getInt("Employee_Number");
-
String name = rs.getString("First_Name");
-
String addr = rs.getString("Second_Name");
-
data = rs.getBinaryStream(1);
-
int temp=0;
-
while( (temp = data.read()) != -1) {
-
out.write(temp); }
-
System.out.println( id + name + addr);
-
}
-
-
out.flush();
-
out.close();
-
-
}
-
-
} catch(Exception e) {
-
System.err.println("Exception: " + e.getMessage());
-
} finally {
-
try {
-
if(con != null)
-
con.close();
-
} catch(SQLException e) {}
-
}
-
}
-
}
Can any one plzz help me soon...
thanks and regards..
senthil
Just try this while loop - while (rs.next()) {
-
int id = rs.getInt("Employee_Number");
-
out.write(id);
-
String name = rs.getString("First_Name");
-
out.write(name);
-
String addr = rs.getString("Second_Name");
-
out.write(addr);
-
}
-
Just try this while loop - while (rs.next()) {
-
int id = rs.getInt("Employee_Number");
-
out.write(id);
-
String name = rs.getString("First_Name");
-
out.write(name);
-
String addr = rs.getString("Second_Name");
-
out.write(addr);
-
}
-
Hai ro35...
thanks for ur reply...
now its writing the data to the file...
But itz not writing the Employee_Number to the file...
the output is like the follwing in the text file..
? Axel Washington
? Arvid Sharma
? Jonas Ginsberg
? Florence Wojokowski
? Sean Washington
?Elizabeth Yamaguchi
its sucessfully writing the two strings but itz not writing the integer id...
what to do for this?
thanks.
senthil.
Hai ro35...
thanks for ur reply...
now its writing the data to the file...
But itz not writing the Employee_Number to the file...
the output is like the follwing in the text file..
? Axel Washington
? Arvid Sharma
? Jonas Ginsberg
? Florence Wojokowski
? Sean Washington
?Elizabeth Yamaguchi
its sucessfully writing the two strings but itz not writing the integer id...
what to do for this?
thanks.
senthil.
try out.write(""+id);
also print the id to the console to make sure you're getting the id right from the database.
And you can call me r035198x rather than ro35, r0, or the rest of those variants.
Hai r035198x...
Very very thanks for ur reply...
Now itz working perfectly...
i'm a beginner to java, jsp...
Now i'm learning hardly to work in java...
can u plzz tell me...
what are the main concepts i have to study in java
to do projects in jsp...
thanks
senthil.
Well why do we need to write it this way?please explain.
try out.write(""+id);
.
Ya i'm also want the reason for hirak's question...
plzz explain us.. r035198x....
thanks.
senthil.
Hai r035198x...
Very very thanks for ur reply...
Now itz working perfectly...
i'm a beginner to java, jsp...
Now i'm learning hardly to work in java...
can u plzz tell me...
what are the main concepts i have to study in java
to do projects in jsp...
thanks
senthil.
Depends really on what you want to do with JSP. If you just want to master it, you can start by making small interesting programs with it. Just trying to come up with some nice system that involves one or two other technologies as well and you'll learn quite a lot about them that way.
Ya i'm also want the reason for hirak's question...
plzz explain us.. r035198x....
thanks.
senthil.
id is an int. Calling write(id) calls a method
different from calling write(""+id); because the second one calls a method that takes a String as argument is more suited for presentation that the first method.
ya okay,
now itz cleared...
thanks for ur support and responses...
senthil.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: apchar |
last post by:
I am trying to use php as a kind of servlet to act as a middle man
between a java applet and mysql. I know java has jdbc but it's flakey
and painful. php access to mysql is much nicer. So I have:...
|
by: NotGiven |
last post by:
I am researching the best place to put pictures. I have heard form both
sides and I'd like to know why one is better than the other.
Many thanks!
|
by: mdh |
last post by:
I am trying to learn the basics of MVC applications using a Tomcat
infrastructure. I'm starting by building a simple application with:
* a login.jsp page for a basic login form with a action...
|
by: Ike |
last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on
111.111.111.111 allowing all incoming and outgoing ports. I have a username
and password setup, which CAN connect to this database,...
|
by: asenthil |
last post by:
Hai,
Can any one tell me,
How to retrive rows in alphabetcal order in the mysql database
by using select query?
thanks..
senthil
| |
by: asenthil |
last post by:
Hai,
i'm having a string in a specific field of a database...
now i want to retrive that string from the database
and i have to write that string into a xml file....
retriving is not a...
|
by: nrip |
last post by:
Dear All,
I am facing a very peculiar problem. I am reading a CSV file from my JSP code and trying to insert them into MYSQL database. the program first reads a line and then splits it into words...
|
by: Atli |
last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t.
In situations where your PHP application...
|
by: amritranjan |
last post by:
How to retrive image file from MS access database and display this in another JSPpage
--------------------------------------------------------------------------------
This is my Jsp code for...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |