This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table vendedor ( | |
codigo_vendedor int not null primary key, | |
nome varchar (50), | |
idade char (3), | |
sexo char (1), | |
salario decimal (10,2) | |
) | |
create table cliente ( | |
codigo_cliente int not null primary key, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table departamentos ( | |
codigo int not null primary key auto_increment, | |
nome varchar (50)); | |
create table funcionarios ( | |
codigo int not null primary key auto_increment, | |
primeiroNome varchar (50) not null, | |
segundoNome varchar (50), | |
ultimoNome varchar (50) not null, | |
dataNascimento date, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table departamentos ( | |
codigo int not null primary key auto_increment, | |
nome varchar (50)); | |
create table funcionarios ( | |
codigo int not null primary key auto_increment, | |
primeiroNome varchar (50) not null, | |
segundoNome varchar (50), | |
ultimoNome varchar (50) not null, | |
dataNascimento date, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Usuario buscaUsuario(int id) throws SQLException { | |
Connection conexaoComBanco = null; | |
PreparedStatement preparedStatement = null; | |
Usuario usuarioEncontrado = null; | |
String consulta = "SELECT EMAIL, NOME WHERE ID = ?"; | |
try { | |
// busca a conexão de algum lugar válido | |
conexaoComBanco = getConexaoComBanco(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void salvarUsuario(Usuario usuario) { | |
EntityManager entityManager = getEntityManager(); | |
entityManager.getTransaction().begin(); | |
entityManager.persist(usuario); | |
entityManager.getTransaction().commit(); | |
entityManager.close(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Usuario buscaUsuario(int id) { | |
EntityManager entityManager = getEntityManager(); | |
Usuario usuario = entityManager.find(Usuario.class, id); | |
entityManager.close(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> | |
<persistence-unit name="seuPU" transaction-type="RESOURCE_LOCAL"> | |
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> | |
<properties> | |
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/seuBanco"/> | |
<property name="javax.persistence.jdbc.password" value="suaSenha"/> | |
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> | |
<property name="javax.persistence.jdbc.user" value="seuUser"/> | |
</properties> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create database locacao; | |
use locacao; | |
create table marca( | |
id int not null primary key auto_increment, | |
descricao varchar(20) | |
); | |
create table modelo( | |
id int not null primary key auto_increment, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Entity | |
public class Marca { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
@Entity | |
public class Modelo { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) |
OlderNewer