Arne...Prøv se det her
import java.util.Iterator;
import java.sql.Timestamp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Blob;
public class Person {
public int id;
public String navn;
public String cpr;
public String adresse;
public String by;
public String tellefon;
public String email;
public String sidstUpDato;
public String beskrivelse;
public Blob b;
public Person(int id, String navn, String cpr, String adresse,
String by, String tellefon, String email, String sidstUpDato,
String beskrivelse,Blob b) {
this.id = id;
this.navn = navn;
this.cpr = cpr;
this.adresse = adresse;
this.by = by;
this.email = email;
this.tellefon = tellefon;
this.email = email;
this.sidstUpDato = sidstUpDato;
this.beskrivelse = beskrivelse;
this.b=b;
}
public Person(int id, String navn, String cpr, String adresse,
String by, String tellefon, String email,
String beskrivelse,Blob b) {
this.id = id;
this.navn = navn;
this.cpr = cpr;
this.adresse = adresse;
this.by = by;
this.email = email;
this.tellefon = tellefon;
this.email = email;
this.beskrivelse = beskrivelse;
this.b=b;
}
public int getId() {
return id;
}
public String getNavn() {
return navn;
}
public String getCPR() {
return cpr;
}
public String getAdresse() {
return adresse;
}
public String getBy() {
return by;
}
public String getTellefon() {
return tellefon;
}
public String getEmail() {
return email;
}
public String getCpr() {
return cpr;
}
public String getsidstUpDato() {
return sidstUpDato;
}
public String getBeskrivelse(){
return beskrivelse;
}
public Blob getBillede(){
return b;
}
public String toString() {
return "Personnens nr: " + getId() + " - " +
"Navn: " + getNavn()+"\n";
}
private static PersonAdministrator getPersonAdministrator(){
return (PersistensAdministrator.getPersonAdministrator());}
public void retStamdata(String navn, String cpr, String adresse,
String by, String tellefon, String email,
String sidstUpDato, String beskrivelse, Blob b) {
this.navn = navn;
this.cpr = cpr;
this.adresse = adresse;
this.by = by;
this.email = email;
this.tellefon = tellefon;
this.email = email;
this.sidstUpDato = sidstUpDato;
this.beskrivelse = beskrivelse;
this.b=b;
PersonAdministrator personAdministrator = getPersonAdministrator();
personAdministrator.replace(this);
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Det er min person beskrivelse
////////////////////////////////////////////////////////////////////////////////
Her kommer PersonAdmistrator
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
import bjbupack.jdb.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PersonAdministrator extends DBObjectAdministrator
{
private int lastKey = 0;
public PersonAdministrator (DBAdministrator dbAdministrator,
String table)
{
super (dbAdministrator, table, "Id","SELECT * FROM "+table);
lastKey = getLastKey();
}
public Object get (int key, int key2)
{
System.out.println("Fejl: der skal anvendes metode med eet nøglerfelt");
throw new UnsupportedOperationException();
}
public boolean contains ( Object object )
{
Person person = (Person)object;
return get(person.getId()) != null;
}
public boolean add ( Object object )
{
Person person = (Person)object;
String sql = "INSERT INTO "+table
+ " ("
+ " [Id]"
+ " ,[Navn]"
+ " ,[CPR]"
+ " ,[Adresse]"
+ " ,[By]"
+ " ,[Tellefon]"
+ " ,[Email]"
+ " ,[sidstUpDato]"
+ " ,[Beskrivelse]"
+ " ,[B]"
+ " ) VALUES "
+ " ("
+ " " +person.getId() +""
+ ", '" +person.getNavn() +"'"
+ ", '" +person.getCPR() +"'"
+ ", '" +person.getAdresse() +"'"
+ ", '" +person.getBy() +"'"
+ ", '" +person.getTellefon() +"'"
+ ", '" +person.getEmail() +"'"
+ ", '" +person.getsidstUpDato() +"'"
+ ", '" +person.getBeskrivelse() +"'"
+ ", '" +person.getBillede() +"'"
+ " )";
return ( executeUpdate (sql) );
}
public boolean remove ( Object object )
{
Person person = (Person)object;
String sql = "DELETE * FROM "+table
+ " WHERE [Id]=" +person.getId() +""
;
return ( executeUpdate (sql) );
}
protected Object convertToObject (ResultSet resultSet)
{
try
{
Person person = new Person ( resultSet.getInt("Id"),
resultSet.getString("Navn"),
resultSet.getString("CPR"),
resultSet.getString("Adresse"),
resultSet.getString("By"),
resultSet.getString("Tellefon"),
resultSet.getString("Email"),
resultSet.getString("sidstUpDato"),
resultSet.getString("Beskrivelse"),
resultSet.getBlob("B")
);
return (person);
}
catch (SQLException e)
{
System.out.println("Fejl ved convertToObject fra "+table);
return (null);
}
}
public boolean replace ( Object object )
{
Person person = (Person)object;
String sql = "UPDATE "+table+" SET"
+ " [Navn]='" +person.getNavn() +"'"
+ ", [CPR]='" +person.getCPR() +"'"
+ ", [Adresse]='" +person.getAdresse() +"'"
+ ", [By]='" +person.getBy() +"'"
+ ", [Tellefon]='" +person.getTellefon() +"'"
+ ", [Email]='" +person.getEmail() +"'"
+ ", [sidstUpDato]='" +person.getsidstUpDato() +"'"
+ ", [Beskrivelse]='" +person.getBeskrivelse() +"'"
+ ", [B]='" +person.getBillede() +"'"
+ " WHERE [Id]=" +person.getId() +""
;
return ( executeUpdate (sql) );
}
public Person NYPerson(
String navn, String cpr, String adresse,String by, String tellefon, String email, String sidstUpDato,String Beskrivelse,Blob B) {
++lastKey;
Person person = new Person ( lastKey, navn, cpr , adresse, by, tellefon, email, sidstUpDato,Beskrivelse,B );
return (person);
}
}