Free web hosts - 520 Part IV . Development Creating a basic

520 Part IV . Development Creating a basic MySQL JDBC Program Building on the simple connection program from the last section, I ll retrieve some results from a query by using the following code: import java.sql.*; public class SimpleSelect { public static void main(String args[]) { String url = jdbc:mysql://localhost/ecommerce ; Connection con; try { Class.forName( org.gjt.mm.mysql.Driver ); } catch(java.lang.ClassNotFoundException e) { System.err.print( ClassNotFoundException: ); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, suehring , evh5150 ); System.out.println( Connection established! ); Statement stmt = con.createStatement(); ResultSet productinfo = stmt.executeQuery( SELECT name,artist FROM product ); while (productinfo.next()) { System.out.println(productinfo.getString( name ) + + productinfo.getString( artist )); } con.close(); } catch(SQLException ex) { System.err.println( SQLException: + ex.getMessage()); } } } The code just given has a new section added to execute the statement and retrieve the results. A Statementobject, stmt, is created. Then the query is issued. The results are then retrieved by using the getString method with the column name in quotes:
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Leave a Reply