Derby JDBC Connection : Java DB Derby « JDK 6 « Java






Derby JDBC Connection

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

import java.util.Properties;

public class MainClass {
   public static void main(String[] args)
   {
      try {
         String driver = "org.apache.derby.jdbc.EmbeddedDriver";

         Class.forName(driver).newInstance();
         Connection conn = null;
         conn = DriverManager.getConnection("jdbc:derby:DerbyTestDB");
         Statement s = conn.createStatement();
         ResultSet rs = s.executeQuery("SELECT city, state, zipcode FROM zipcodes");

         while(rs.next()) {
            System.out.println("City   : "+ rs.getString(1));
            System.out.println("State  : "+ rs.getString(2));
            System.out.println("Zipcode: "+ rs.getString(3));
            System.out.println();
         }

         rs.close();
         s.close();
         conn.close();
      } catch(Exception e) {
         System.out.println("Exception: "+ e);
         e.printStackTrace();
      }
   }
}

           
       








DerbyJDBCConnection.zip( 4,054 k)

Related examples in the same category

1.Connect to Java DB (Derby) with org.apache.derby.jdbc.EmbeddedDriver
2.Derby ISQL