Javatpoint Logo

how to fetch online database value in jdbc connection

By: ramani*** On: Wed Jun 22 12:24:57 IST 2016     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
using online database linkUp0Down

 


Retrieving and Modifying Values from Result Sets

public static void viewTable(Connection con, String dbName)
throws SQLException {

Statement stmt = null;
String query =
"select COF_NAME, SUP_ID, PRICE, " +
"SALES, TOTAL " +
"from " + dbName + ".COFFEES";

try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + "\t" + supplierID +
"\t" + price + "\t" + sales +
"\t" + total);
}
} catch (SQLException e ) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
if (stmt != null) { stmt.close(); }
}
}
Image Created0Down

By: [email protected] On: Thu Jun 23 07:17:22 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No