Java Retrieve Table Contents
Chapter:
JDBC
Last Updated:
10-09-2016 06:54:24 UTC
Program:
/* ............... START ............... */
import java.sql.*;
public class JavaRetrieveTableContents {
public static void main(String[] args) {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException e) {
System.out.println("Class not found " + e);
}
try {
Connection con = DriverManager.
getConnection("jdbc:derby://localhost:1527/testDb", "username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM employee");
System.out.println("id name job");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String job = rs.getString("job");
System.out.println(id + " " + name + " " + job);
}
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
}
}
/* ............... END ............... */
Tags
Retrieve Table Contents Java, JDBC