Search This Blog

Total Pageviews

Program to Retrieve Table Contents using JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

 * -- Use try-resource to auto close the resources.  
public class RetrieveTableContents
       public static void main(String[] args) {
          try {
          catch(ClassNotFoundException e) {
             System.out.println("Class not found "+ e);
          try {
             Connection connection = DriverManager.getConnection
             try( Statement stmt = connection.createStatement()){
                 ResultSet rs = stmt.executeQuery
                         ("SELECT * FROM Table_name");
                 System.out.println("id  name    job");
                 while (rs.next()) {
                     int id = rs.getInt("id");
                     String col1 = rs.getString("ColName");
                     String col2 = rs.getString("ColName");
                     System.out.println(id+"   "+col1+"    "+col2);
          catch(SQLException e){
             System.out.println("SQL exception occured" + e);

No comments:

gradlew : The term 'gradlew' is not recognized as the name of a cmdlet, function, script file , or operable program

The command gradlew was not found, but does exist in the current location.  Windows PowerShell does not load commands from the current locat...