[ Foro de Java ]
Hola chicos malos.
Pues este codigo consiste en registrar datos de netbeans a my sql, el detalle es que me da este error:
Aqui les dejo el codigo:
package asfdasfdsfdasfdasfd;
// Importamos las clases de conexion a mysql y los drivers de sql
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Level;
import static java.util.logging.Level.SEVERE;
import java.util.logging.Logger;
/**
*
* @author windows
*/
public class Playeram extends javax.swing.JFrame {
// Declaramos la conexion a mysql
private static Connection con;
// Declaramos los datos de conexion a la bd
private static final String driver="com.mysql.jdbc.Driver";
private static final String user="root";
private static final String pass="";
private static final String url="jdbc:mysql://localhost:3306/tiendita";
PreparedStatement pps;
ResultSet rs;
/**
* Creates new form Playeram
*/
private void limpiarCajas (){
elnombre.setText(null);
elnumero.setText(null);
ladireccion.setText(null);
}
// Funcion que va conectarse a mi bd de mysql
public void conector() {
// Reseteamos a null la conexion a la bd
con=null;
try{
Class.forName(driver);
// Nos conectamos a la bd
con= (Connection) DriverManager.getConnection(url, user, pass);
// Si la conexion fue exitosa mostramos un mensaje de conexion exitosa
if (con!=null){
JOptionPane.showMessageDialog(null,"Conexion establecida");
}
}
// Si la conexion NO fue exitosa mostramos un mensaje de error
catch (SQLException e){
JOptionPane.showMessageDialog(null,"Error de conexion" + e);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Playeram.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Playeram() {
initComponents();
this.setLocationRelativeTo(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
elcolor = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
eltamaño = new javax.swing.JComboBox<>();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
elnombre = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
elnumero = new javax.swing.JTextField();
ladireccion = new javax.swing.JTextField();
Regresar = new javax.swing.JButton();
Cancelar = new javax.swing.JButton();
Avanzar = new javax.swing.JButton();
Producto = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
elcolor.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
elcolorActionPerformed(evt);
}
});
jLabel1.setText("Color:");
eltamaño.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Chica", "Mediana", "Grande", "Extra Grande" }));
eltamaño.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eltamañoActionPerformed(evt);
}
});
jLabel2.setText("Talla:");
jLabel3.setText("Nombre:");
elnombre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
elnombreActionPerformed(evt);
}
});
jLabel4.setText("Numero de telefono:");
jLabel5.setText("Direccion:");
elnumero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
elnumeroActionPerformed(evt);
}
});
ladireccion.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ladireccionActionPerformed(evt);
}
});
Regresar.setText("Regresar");
Regresar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RegresarActionPerformed(evt);
}
});
Cancelar.setText("Cancelar");
Cancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CancelarActionPerformed(evt);
}
});
Avanzar.setText("Avanzar");
Avanzar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AvanzarActionPerformed(evt);
}
});
Producto.setText("Nombre:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(97, 97, 97)
.addComponent(jLabel5))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(Producto, javax.swing.GroupLayout.Alignment.TRAILING))))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ladireccion)
.addComponent(elnumero)
.addComponent(elnombre)
.addComponent(eltamaño, 0, 524, Short.MAX_VALUE)
.addComponent(elcolor)
.addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(Regresar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
.addComponent(Cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(54, 54, 54)
.addComponent(Avanzar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(113, 113, 113))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(47, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Producto)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(elnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(elnumero, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ladireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(eltamaño, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(elcolor, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(86, 86, 86)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Cancelar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
.addComponent(Regresar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(Avanzar, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(30, 30, 30))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {
elcolor.setText("");
eltamaño.setSelectedIndex(0);
ladireccion.setText("");
elnumero.setText("");
elnombre.setText("");
}
private void RegresarActionPerformed(java.awt.event.ActionEvent evt) {
elcolor.setText("");
ladireccion.setText("");
elnumero.setText("");
elnombre.setText("");
eltamaño.setSelectedIndex(0);
Interfaz I = new Interfaz();
I.setVisible(true);
dispose();
}
private void AvanzarActionPerformed(java.awt.event.ActionEvent evt) {
conector();
Connection con = null;
try{
con = getConection();
pps = (PreparedStatement) con.prepareStatement("INSERT INTO cliente(Nombre, Direccion, Numero de telefono)VALUES(?,?,?)");
pps.setString(1,elnombre.getText());
pps.setString(2,ladireccion.getText());
pps.setString(3,elnumero.getText());
int res = pps.executeUpdate();
if(res > 0 ){
JOptionPane.showMessageDialog(null, "Persona Guardada");
limpiarCajas();
} else{
JOptionPane.showMessageDialog(null, "error");
limpiarCajas();
}
con.close();
} catch(Exception e){
System.err.println(e);
}
PlayeraF PF = new PlayeraF();
String color = elcolor.getText();
PlayeraF.colores.setText(color);
String nombre = elnombre.getText();
PlayeraF.nombres.setText(nombre);
String direccion = ladireccion.getText();
PlayeraF.direcciones.setText(direccion);
String numerocel = elnumero.getText();
PlayeraF.numeros.setText(numerocel);
String tamaño = eltamaño.getSelectedItem().toString();
PlayeraF.tamaños.setText(tamaño);
PF.setVisible(true);
dispose();
}
private void eltamañoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void elcolorActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void elnombreActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void elnumeroActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ladireccionActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Playeram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Playeram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Playeram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Playeram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Playeram().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Avanzar;
private javax.swing.JButton Cancelar;
private javax.swing.JLabel Producto;
private javax.swing.JButton Regresar;
private javax.swing.JTextField elcolor;
private javax.swing.JTextField elnombre;
private javax.swing.JTextField elnumero;
private javax.swing.JComboBox<String> eltamaño;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField ladireccion;
// End of variables declaration
private Connection getConection() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)