LINK DO QUESTIONÁRIO
quinta-feira, 30 de novembro de 2017
segunda-feira, 6 de novembro de 2017
Executar Relatorio no Java (IREPORT)
MENU RELATÓRIO -> (EXECUÇÃO DO IREPORT)
Connection con = ConnectionFactory.getConnection();
int confirma = JOptionPane.showConfirmDialog(null, "Confirma?", "Atenção", JOptionPane.YES_NO_OPTION);
if (confirma == JOptionPane.YES_OPTION) {
try {
JasperPrint print = JasperFillManager.fillReport("C:\\report\\Relatorio2.jasper", null, con);
JasperViewer.viewReport(print, false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
Connection con = ConnectionFactory.getConnection();
int confirma = JOptionPane.showConfirmDialog(null, "Confirma?", "Atenção", JOptionPane.YES_NO_OPTION);
if (confirma == JOptionPane.YES_OPTION) {
try {
JasperPrint print = JasperFillManager.fillReport("C:\\report\\Relatorio2.jasper", null, con);
JasperViewer.viewReport(print, false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
quarta-feira, 23 de agosto de 2017
segunda-feira, 21 de agosto de 2017
Metodo para Buscar no banco por login
Colocar logo abaixo de readTable() - >
public void readJTableForDesc(String desc) {
DefaultTableModel modelo = (DefaultTableModel)tabela.getModel();
modelo.setNumRows(0);
UsuarioDAO pdao = new UsuarioDAO();
for (Usuario p : pdao.readForDesc(desc)) {
modelo.addRow(new Object[]{
p.getId(),
p.getLogin(),
p.getSenha()
});
}
}
public void readJTable() {
DefaultTableModel modelo = (DefaultTableModel) jTProdutos.getModel();
modelo.setNumRows(0);
ProdutoDAO pdao = new ProdutoDAO();
for (Produto p : pdao.read()) {
modelo.addRow(new Object[]{
p.getId(),
p.getDescricao(),
p.getQtd(),
p.getPreco()
});
}
}
public void readJTableForDesc(String desc) {
DefaultTableModel modelo = (DefaultTableModel)tabela.getModel();
modelo.setNumRows(0);
UsuarioDAO pdao = new UsuarioDAO();
for (Usuario p : pdao.readForDesc(desc)) {
modelo.addRow(new Object[]{
p.getId(),
p.getLogin(),
p.getSenha()
});
}
}
public void readJTable() {
DefaultTableModel modelo = (DefaultTableModel) jTProdutos.getModel();
modelo.setNumRows(0);
ProdutoDAO pdao = new ProdutoDAO();
for (Produto p : pdao.read()) {
modelo.addRow(new Object[]{
p.getId(),
p.getDescricao(),
p.getQtd(),
p.getPreco()
});
}
}
Botão Excluir
Clique duplo no botão excluir e use o codigo abaixo:
if (tabela.getSelectedRow() != -1) {
Usuario u = new Usuario();
UsuarioDAO dao = new UsuarioDAO();
u.setId((int) tabela.getValueAt(tabela.getSelectedRow(), 0));
dao.delete(p);
txtLogin.setText("");
txtSenha.setText("");
readTable();
} else {
JOptionPane.showMessageDialog(null, "Selecione um produto para excluir.");
}
if (tabela.getSelectedRow() != -1) {
Usuario u = new Usuario();
UsuarioDAO dao = new UsuarioDAO();
u.setId((int) tabela.getValueAt(tabela.getSelectedRow(), 0));
dao.delete(p);
txtLogin.setText("");
txtSenha.setText("");
readTable();
} else {
JOptionPane.showMessageDialog(null, "Selecione um produto para excluir.");
}
Botão Alterar
if (jTProdutos.getSelectedRow() != -1) {
Usuario u = new Usuario();
UsuarioDAO dao = new UsuarioDAO();
u.setLogin(txtLogin.getText());
u.setSenha(txtSenha.getText());
u.setId((int) tabela.getValueAt(tabela.getSelectedRow(), 0));
dao.update(u);
txtLogin.setText("");
txtSenha.setText("");
readJTable();
}
Enviar do JTable para os campos
Clicar com o botão direito do mouse sobre o JTable - no menu ir até a opção eventos --> Mouse --> mouseclicked
em seguida colar o código abaixo
if (tabela.getSelectedRow() != -1) {
txtLogin.setText(tabela.getValueAt(tabela.getSelectedRow(), 1).toString());
txtSenha.setText(tabela.getValueAt(tabela.getSelectedRow(), 2).toString());
}
em seguida colar o código abaixo
if (tabela.getSelectedRow() != -1) {
txtLogin.setText(tabela.getValueAt(tabela.getSelectedRow(), 1).toString());
txtSenha.setText(tabela.getValueAt(tabela.getSelectedRow(), 2).toString());
}
quarta-feira, 9 de agosto de 2017
FICHA DE INSCRIÇÃO SALÃO DE PROJETOS 2017/2
PESSOAL,
ABAIXO O FORMULÁRIO PARA O CADASTRO DOS GRUPOS PARA O SALÃO DE PROJETOS - FAVOR PREENCHER ATÉ O DIA 15/08/2017
CLIQUE NO LINK: CADASTRO
ABAIXO O FORMULÁRIO PARA O CADASTRO DOS GRUPOS PARA O SALÃO DE PROJETOS - FAVOR PREENCHER ATÉ O DIA 15/08/2017
CLIQUE NO LINK: CADASTRO
segunda-feira, 7 de agosto de 2017
classe Dao
package br.ulbra.model.dao;
import br.ulbra.connection.ConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Jeferson Leon
*/
public class UsuarioDAO {
Connection con;
public UsuarioDAO() {
con = ConnectionFactory.getConnection();
}
//MÉTODO CRIADO PARA INSERIR USUÁRIO NO BANCO DE DADOS
public void create(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("INSERT INTO usuario (login,senha) VALUES (?,?)");
stmt.setString(1, u.getLogin());
stmt.setString(2, u.getSenha());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Usuário Salvo com sucesso!");
} catch (SQLException ex) {
System.out.println(ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
// MÉTODO CRIADO PARA EXCLUIR DO BANCO DE DADOS
public void delete(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("DELETE FROM usuario WHERE id = ?");
stmt.setInt(1, u.getId());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Excluido com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao excluir: " + ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
//MÉTODO CRIADO PARA MODIFICAR NO BANCO DE DADOS
public void update(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("UPDATE usuario SET login = ? , senha= ? WHERE id = ?");
stmt.setString(1, u.getLogin());
stmt.setString(2, u.getSenha());
stmt.setInt(3, u.getId());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Atualizado com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao atualizar: " + ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
//MÉTODOS CRIADOS PARA FAZER PESQUISAS NO BANCO DE DADOS
//EM ORDEM DE CADASTRO TODOS
public ArrayList<Usuario> read() {
PreparedStatement stmt = null;
ResultSet rs = null;
List<Usuario> usuarios = new ArrayList<>();
try {
stmt = con.prepareStatement("SELECT * FROM Usuario");
rs = stmt.executeQuery();
while (rs.next()) {
Usuario usuario = new Usuario();
usuario.setId(rs.getInt("id"));
usuario.setLogin(rs.getString("login"));
usuarios.add(usuario);
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return usuarios;
}
//PESQUISA PELO LOGIN
public List<Usuario> readForDesc(String desc) {
PreparedStatement stmt = null;
ResultSet rs = null;
ArrayList<Usuario> usuarios = new ArrayList<>();
try {
stmt = con.prepareStatement("SELECT * FROM usuario WHERE login LIKE ?");
stmt.setString(1, "%"+desc+"%");
rs = stmt.executeQuery();
while (rs.next()) {
Usuario usuario= new Usuario();
usuario.setId(rs.getInt("id"));
usuario.setLogin(rs.getString("login"));
usuarios.add(usuario);
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return usuarios;
}
public boolean checkLogin(String login, String senha) {
PreparedStatement stmt = null;
ResultSet rs = null;
boolean check = false;
try {
stmt = con.prepareStatement("SELECT * FROM usuario WHERE login = ? and senha = ?");
stmt.setString(1, login);
stmt.setString(2, senha);
rs = stmt.executeQuery();
if (rs.next()) {
check = true;
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return check;
}
}
import br.ulbra.connection.ConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Jeferson Leon
*/
public class UsuarioDAO {
Connection con;
public UsuarioDAO() {
con = ConnectionFactory.getConnection();
}
//MÉTODO CRIADO PARA INSERIR USUÁRIO NO BANCO DE DADOS
public void create(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("INSERT INTO usuario (login,senha) VALUES (?,?)");
stmt.setString(1, u.getLogin());
stmt.setString(2, u.getSenha());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Usuário Salvo com sucesso!");
} catch (SQLException ex) {
System.out.println(ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
// MÉTODO CRIADO PARA EXCLUIR DO BANCO DE DADOS
public void delete(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("DELETE FROM usuario WHERE id = ?");
stmt.setInt(1, u.getId());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Excluido com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao excluir: " + ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
//MÉTODO CRIADO PARA MODIFICAR NO BANCO DE DADOS
public void update(Usuario u) {
PreparedStatement stmt = null;
try {
stmt = con.prepareStatement("UPDATE usuario SET login = ? , senha= ? WHERE id = ?");
stmt.setString(1, u.getLogin());
stmt.setString(2, u.getSenha());
stmt.setInt(3, u.getId());
stmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Atualizado com sucesso!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Erro ao atualizar: " + ex);
} finally {
ConnectionFactory.closeConnection(con, stmt);
}
}
//MÉTODOS CRIADOS PARA FAZER PESQUISAS NO BANCO DE DADOS
//EM ORDEM DE CADASTRO TODOS
public ArrayList<Usuario> read() {
PreparedStatement stmt = null;
ResultSet rs = null;
List<Usuario> usuarios = new ArrayList<>();
try {
stmt = con.prepareStatement("SELECT * FROM Usuario");
rs = stmt.executeQuery();
while (rs.next()) {
Usuario usuario = new Usuario();
usuario.setId(rs.getInt("id"));
usuario.setLogin(rs.getString("login"));
usuarios.add(usuario);
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return usuarios;
}
//PESQUISA PELO LOGIN
public List<Usuario> readForDesc(String desc) {
PreparedStatement stmt = null;
ResultSet rs = null;
ArrayList<Usuario> usuarios = new ArrayList<>();
try {
stmt = con.prepareStatement("SELECT * FROM usuario WHERE login LIKE ?");
stmt.setString(1, "%"+desc+"%");
rs = stmt.executeQuery();
while (rs.next()) {
Usuario usuario= new Usuario();
usuario.setId(rs.getInt("id"));
usuario.setLogin(rs.getString("login"));
usuarios.add(usuario);
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return usuarios;
}
public boolean checkLogin(String login, String senha) {
PreparedStatement stmt = null;
ResultSet rs = null;
boolean check = false;
try {
stmt = con.prepareStatement("SELECT * FROM usuario WHERE login = ? and senha = ?");
stmt.setString(1, login);
stmt.setString(2, senha);
rs = stmt.executeQuery();
if (rs.next()) {
check = true;
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
} finally {
ConnectionFactory.closeConnection(con, stmt, rs);
}
return check;
}
}
Botão Logar
UsuarioDAO dao = new UsuarioDAO();
if(dao.checkLogin(txtLogin.getText(), txtSenha.getText())){
new ViewHome().setVisible(true);
this.dispose();
}else{
JOptionPane.showMessageDialog(null, "Senha incorreta!");
}
}
if(dao.checkLogin(txtLogin.getText(), txtSenha.getText())){
new ViewHome().setVisible(true);
this.dispose();
}else{
JOptionPane.showMessageDialog(null, "Senha incorreta!");
}
}
Classe ConnectionFactory
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConnectionFactory {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/dbsistemacsl";
private static final String USER = "root";
private static final String PASS = "";
public static Connection getConnection() {
try {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USER, PASS);
} catch (ClassNotFoundException | SQLException ex) {
throw new RuntimeException("Erro na conexão: ", ex);
}
}
public static void closeConnection(Connection con) {
try {
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(
Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt) {
closeConnection(con);
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(
Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt,
ResultSet rs) {
closeConnection(con, stmt);
try {
if (rs != null) {
rs.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConnectionFactory {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/dbsistemacsl";
private static final String USER = "root";
private static final String PASS = "";
public static Connection getConnection() {
try {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USER, PASS);
} catch (ClassNotFoundException | SQLException ex) {
throw new RuntimeException("Erro na conexão: ", ex);
}
}
public static void closeConnection(Connection con) {
try {
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(
Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt) {
closeConnection(con);
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(
Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt,
ResultSet rs) {
closeConnection(con, stmt);
try {
if (rs != null) {
rs.close();
}
} catch (SQLException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
quinta-feira, 2 de março de 2017
CAPA DO DIÁRIO DE BORDO
DOWNLOAD
MODELO DO RELATÓRIO DA FIT
DOWNLOAD
EXEMPLOS DE RELATORIOS DESENVOLVIDOS
MECATRÔNICA
EXEMPLO 1 - CAIXA DE CORREIO INTELIGENTE
INFORMÁTICA
EXEMPLO 1 - WEBBUS
EXEMPLO 2 - ORGANIZA-PRÓ
DOWNLOAD
MODELO DO RELATÓRIO DA FIT
DOWNLOAD
EXEMPLOS DE RELATORIOS DESENVOLVIDOS
MECATRÔNICA
EXEMPLO 1 - CAIXA DE CORREIO INTELIGENTE
INFORMÁTICA
EXEMPLO 1 - WEBBUS
EXEMPLO 2 - ORGANIZA-PRÓ
Assinar:
Comentários (Atom)