Ejemplo clases

<?php
        //Enter your code here, enjoy!
class empleado {
    public $sueldo;
    private $nombre;
function paga(){
return $this->sueldo/12;
}
public function __get($propiedad) {
if (property_exists($this, $propiedad)) {
return $this->$propiedad;
}
}
public function __set($property, $value) {
if (property_exists($this, $property)) {
   if (!empty($value)){
$this->$property = $value;
   }
}
}
}
class comercial extends empleado{
    public $comision=.1;
    public $ventas=200000;
function paga(){
$p=parent::paga();
return $p+$this->ventas*$this->comision/12;
}
}
$juan= new empleado();
$juan->nombre=”Juan”;
echo $juan->nombre;
$juan->nombre=””;
echo $juan->nombre;
$juan->sueldo=30000;
echo $juan->paga().”|”;
$ana=new comercial();
$ana->sueldo=30000;
echo $ana->paga();

Acceso a datos JDBC

import java.math.BigDecimal;
import java.sql.*;


public class Derby {

 public static void main(String[] args) {

 try (Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/JavaTunesDB", "guest",
 "password");) {
 // rest of code

 String sql = "SELECT ITEM_ID, Title, Price FROM ITEM";

 // conn is connection as from previous slide
 // create a Statement object
 Statement stmt = conn.createStatement();
 // execute the SQL with it
 ResultSet rs = stmt.executeQuery(sql);
 while (rs.next()) {
 long id = rs.getLong("ITEM_ID");
 String title = rs.getString("Title");
 BigDecimal price = rs.getBigDecimal("Price");
 System.out.println(id + "," + title + "," + price);
 } // Do something with data (not shown)
 
 
 sql = "SELECT Title, Price FROM ITEM " +
 "WHERE ITEM_ID = ?";
 
 PreparedStatement pstmt = conn.prepareStatement(sql);
 // set the ? - they are numbered starting at 1
 pstmt.setInt(1, 10);
 // execute the PreparedStatement and get a ResultSet
 rs = pstmt.executeQuery();
 
 rs.next();
 String title = rs.getString("Title");
 Double price = rs.getDouble("Price");
 System.out.println(title + "," + price);
 
 
 } catch (SQLException sqle) {
 System.out.println(sqle.getMessage());
 }
 }

}