import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc5
{
public static void main(String[] args)throws ClassNotFoundException
{
// Loading & Register the Type-1 Driver Class(JdbcOdbcDriver). But this line is optional
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Establishing the connection
try(Connection con=DriverManager.getConnection("jdbc:odbc:alt","system","manager"))
{
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
ResultSet rs=st.executeQuery("select * from emp");
System.out.println("ID\tName\tSalary");
System.out.println("--------------------------------------");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getFloat(3));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc5
{
public static void main(String[] args)throws ClassNotFoundException
{
// Loading & Register the Type-1 Driver Class(JdbcOdbcDriver). But this line is optional
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Establishing the connection
try(Connection con=DriverManager.getConnection("jdbc:odbc:alt","system","manager"))
{
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
ResultSet rs=st.executeQuery("select * from emp");
System.out.println("ID\tName\tSalary");
System.out.println("--------------------------------------");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getFloat(3));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
0 Comment to "Jdbc Program to retrieve all data from 'emp' table of oracle database type-1 driver."
Post a Comment