desavera/pupil1 — pull request #1 by Led-ds (2014-10-13 20:15:42+00:00)
Title: Create Bread

Classe Modelo

package com.alexss.daoContato;

import com.alexss.conexao.ConectJDBC;
import com.alexss.modelo.Contato;

import java.sql.*;
import java.text.DateFormat;
import java.text.ParseException;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Negocio extends ConectJDBC{

private Connection conn = null;
private Statement stmt = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
private ConectJDBC conect;

private Calendar formtData;

public SimpleDateFormat novoFormato = null;
public Date data = null;

public boolean Save(Contato c){

conect = new ConectJDBC();

boolean conectado = false;

if(conect != null ){
conect.OpenConnect();
}

try {
data = formataData(c.getData());
System.out.println(data);
} catch (Exception e) {
e.printStackTrace();
}

try{

String query = "INSERT INTO contato(matricula, name, data)"+
"VALUE (" + c.getMatricula() + ",'" + c.getNome() + "','" + data + "')";
pstmt.execute(query);
conectado = true;
}
catch (SQLException exp){
exp.printStackTrace();
System.out.println("Not Execute your Query..." + exp);
}
return conectado;
}

public Date formataData(String data) throws ParseException {
if (data == null || data.equals(""))
return null;

Date dt = new Date();
novoFormato = new SimpleDateFormat("dd/MM/yyyy");
dt = novoFormato.parse(data);

System.out.println(novoFormato.format(dt));

return dt;
}

}