JDBC

JDBC Projects

JDBC Project 1

adplus-dvertising
JDBC Using Statement example – Select all records from database table
Previous Home Next
/*This example shows to how to fetch all the rows 
from the database table using JDBC Statement.*/

package r4r;
import java.sql.*;
public class AllDataFetch
{
public static void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
ResultSet rset=stmt.executeQuery("select * from user5" );
while(rset.next())
{
System.out.println
(rset.getString(1)+"\t"+rset.getInt(2)+"\t"
+rset.getString(3)+"\t"+rset.getString(4));
}
System.out.println("successfully fetched");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

output:

vineet 2 noida m
swarna 5 Goa f
sashi 3 gr8noida m
gaurav 1 noida m
raghav 4 ghaziabad m
successfully fetched
Previous Home Next