@Vyctorhenrique99 escreveu:
Não está inserindo na tabela:
package SoUmJoguinho; import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JOptionPane; import java.awt.Font; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.JCheckBox; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.sql.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.awt.event.ActionEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.ImageIcon; import java.awt.event.MouseAdapter; public class Cadastro extends JFrame { Connection connection = null; Statement stmt = null; private JPanel contentPane; private JTextField txtNome; private JTextField txtSobrenome; private JTextField txtEmail; private JTextField txtSenha; public static void main(String[] args) { EventQueue.invokeLater ( new Runnable() { public void run() { try { Cadastro frame = new Cadastro(); frame.setVisible(true); frame.setLocationRelativeTo(null); } catch (Exception e) { e.printStackTrace(); } } } ); } public Cadastro() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 650, 500); setResizable(false); setUndecorated(true); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblCadastrese = new JLabel("Cadastre-se"); lblCadastrese.setFont(new Font("Tahoma", Font.PLAIN, 32)); lblCadastrese.setBounds(237, 46, 200, 56); contentPane.add(lblCadastrese); JButton button = new JButton(""); button.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { } }); button.setBorder(null); button.setBorderPainted(false); button.setContentAreaFilled(false); button.setOpaque(false); button.setBounds(275, 25, 91, 23); contentPane.add(button); txtNome = new JTextField(); txtNome.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent arg0) { if (txtNome.getText().equals("Nome")) { txtNome.setText(""); } } public void focusLost(FocusEvent e) { if (txtNome.getText().equals("")) { txtNome.setText("Nome"); } } }); txtNome.setText("Nome"); txtNome.setBounds(197, 113, 254, 23); txtNome.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(txtNome); txtNome.setColumns(10); txtSobrenome = new JTextField(); txtSobrenome.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent arg0) { if (txtSobrenome.getText().equals("Sobrenome")) { txtSobrenome.setText(""); } } public void focusLost(FocusEvent e) { if (txtSobrenome.getText().equals("")) { txtSobrenome.setText("Sobrenome"); } } }); txtSobrenome.setText("Sobrenome"); txtSobrenome.setBounds(197, 147, 254, 23); txtSobrenome.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(txtSobrenome); txtSobrenome.setColumns(10); txtEmail = new JTextField(); txtEmail.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent arg0) { if (txtEmail.getText().equals("Digite seu E-mail")) { txtEmail.setText(""); } } public void focusLost(FocusEvent e) { if (txtEmail.getText().equals("")) { txtEmail.setText("Digite seu E-mail"); } } }); txtEmail.setText("Digite seu E-mail"); txtEmail.setBounds(196, 181, 255, 23); txtEmail.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(txtEmail); txtEmail.setColumns(10); txtSenha = new JTextField(); txtSenha.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent arg0) { if (txtSenha.getText().equals("Digite uma Senha")) { txtSenha.setText(""); } } public void focusLost(FocusEvent e) { if (txtSenha.getText().equals("")) { txtSenha.setText("Digite uma Senha"); } } }); txtSenha.setHorizontalAlignment(SwingConstants.CENTER); txtSenha.setText("Digite uma Senha"); txtSenha.setBounds(197, 215, 254, 20); contentPane.add(txtSenha); txtSenha.setColumns(10); JButton btnOk = new JButton("Ok"); String a = txtEmail.getText(); JCheckBox chckbxEuConcordo = new JCheckBox("Eu concordo com os Termos de Licen\u00E7a e Uso"); chckbxEuConcordo.setBounds(192, 242, 319, 23); chckbxEuConcordo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(chckbxEuConcordo.isSelected()) { btnOk.setEnabled(true); } else { btnOk.setEnabled(false); } } }); contentPane.add(chckbxEuConcordo); btnOk.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) { if(txtNome.getText()==null || txtNome.getText().trim().equals("Nome")) { JOptionPane.showMessageDialog(null,"Preencha o campo Nome","Error Name",JOptionPane.ERROR_MESSAGE); } else { if(txtSobrenome.getText()==null || txtSobrenome.getText().trim().equals("Sobrenome")) { JOptionPane.showMessageDialog(null,"Preencha o campo Sobrenome","Error Lastname ",JOptionPane.ERROR_MESSAGE); } else { if(txtEmail.getText()==null || txtEmail.getText().trim().equals("Digite seu E-mail")) { JOptionPane.showMessageDialog(null,"Preencha o campo E-mail","Error Email ",JOptionPane.ERROR_MESSAGE); } else { if(txtSenha.getText()==null || txtSenha.getText().trim().equals("Digite uma Senha")) { JOptionPane.showMessageDialog(null,"Preencha o campo Senha","Error Password ",JOptionPane.ERROR_MESSAGE); } else { try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:8080/phpmyadmin", "root", ""); stmt = connection.createStatement(); stmt.executeUpdate("insert into Cadastro (NICKNAME,USERNAME,PASSWORD,E-MAIL) values ('"+txtNome.getText()+"','"+txtSobrenome.getText()+"','"+txtSenha.getText()+"','"+txtEmail.getText()+"')"); JOptionPane.showMessageDialog(rootPane, "Cadastro Feito com Sucesso"); } catch (ClassNotFoundException ex) { System.out.println("Não foi possível carregar o driver."); ex.printStackTrace(); } catch (SQLException ex) { System.out.println("Problema com o SQL"); ex.printStackTrace(); } String driver = "com.mysql.jdbc.Driver"; // Classe do driver JDBC // String banco = "soumjoguinho"; // Nome do Banco criado // String host = "localhost"; // Maquina onde está o banco // String str_conn = "jdbc:mysql://" + host + ":8080/" + banco; // URL de conexão // String usuario = "root"; // Usuário do banco // String senha = ""; try { Class.forName(driver); //Carrega o driver // ****** Obtém a conexão com o banco ****** // Connection conn = DriverManager.getConnection(str_conn, usuario, senha); System.out.println("Conexao com Databases ok"); Statement stmt = conn.createStatement(); String sql = "select * from Cadastro"; ResultSet rs = stmt.executeQuery(sql); String dados= ""; while (rs.next()) { dados= rs.getString(1).toString()+ " "+ rs.getString(2)+ " "+ rs.getString(3)+ " "+ rs.getString(4)+ " "+rs.getString(5).toString(); JOptionPane.showMessageDialog(null, dados + "\n"); } rs.close(); } catch (ClassNotFoundException ex) { System.out.println("Não foi possível carregar o driver."); ex.printStackTrace(); } catch (SQLException ex) { System.out.println("Problema com o SQL"); ex.printStackTrace(); } } Login login = new Login(); login.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); login.setLocationRelativeTo(null); login.setVisible(true); dispose(); } } } } }); btnOk.setFont(new Font("Tahoma", Font.PLAIN, 18)); btnOk.setBounds(286, 272, 62, 28); btnOk.setEnabled(false); contentPane.add(btnOk); JButton btnFacebook = new JButton(""); btnFacebook.setIcon(new ImageIcon("C:\\Users\\Victor\\workspace\\SoUmJoguinho\\src\\SoUmJoguinho\\imagens\\Face.png")); btnFacebook.setBounds(185, 347, 137, 87); btnFacebook.setBorder(null); btnFacebook.setBorderPainted(false); btnFacebook.setContentAreaFilled(false); btnFacebook.setOpaque(false); contentPane.add(btnFacebook); JButton btnSpotify = new JButton(""); btnSpotify.setIcon(new ImageIcon("C:\\Users\\Victor\\workspace\\SoUmJoguinho\\src\\SoUmJoguinho\\imagens\\Spotify.png")); btnSpotify.setBounds(333, 347, 118, 87); btnSpotify.setBorder(null); btnSpotify.setBorderPainted(false); btnSpotify.setContentAreaFilled(false); btnSpotify.setOpaque(false); contentPane.add(btnSpotify); JButton btnWwwsitedodesenvolverdorcombr = new JButton("www.sitedodesenvolverdor.com.br"); btnWwwsitedodesenvolverdorcombr.setForeground(new Color(0, 102, 255)); btnWwwsitedodesenvolverdorcombr.addMouseListener(new MouseAdapter() { @Override public void mouseExited(MouseEvent arg0) { btnWwwsitedodesenvolverdorcombr.setForeground(new Color(0, 102, 255)); } @Override public void mouseEntered(MouseEvent e) { btnWwwsitedodesenvolverdorcombr.setForeground(Color.blue); } }); btnWwwsitedodesenvolverdorcombr.setBounds(217, 321, 200, 15); btnWwwsitedodesenvolverdorcombr.setBorder(null); btnWwwsitedodesenvolverdorcombr.setBorderPainted(false); btnWwwsitedodesenvolverdorcombr.setContentAreaFilled(false); btnWwwsitedodesenvolverdorcombr.setOpaque(false); contentPane.add(btnWwwsitedodesenvolverdorcombr); JButton btnSair = new JButton(""); btnSair.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); btnSair.setIcon(new ImageIcon("C:\\Users\\Victor\\workspace\\SoUmJoguinho\\src\\SoUmJoguinho\\imagens\\Fechar.png")); btnSair.setBounds(606, 11, 34, 39); btnSair.setBorder(null); btnSair.setBorderPainted(false); btnSair.setContentAreaFilled(false); btnSair.setOpaque(false); contentPane.add(btnSair); } }
Mensagens: 3
Participantes: 2