Problema con Jtable
Hola disculpa estoy aprendiendo JTables pero al momento de darle clic a un boton que hice, me manda un error, puedes revisarlo por favor y si no es mucha molestia, corregirlo? Te lo agradeceria mucho
Este es mi codigo:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package visRSJtable2;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Administrador
*/
public class Conexion {
private Connection con;
private PreparedStatement st;
// private ResultSet resultado;
public Conexion() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pruebadb", "root", "sa");
// st = con.prepareStatement("SELECT * FROM tbldatos");
// rs1 = st.executeQuery();
} catch (SQLException sqlException) {
System.out.println(sqlException.getMessage() + "Error en la Base de Datos");
System.exit(1);
} catch (ClassNotFoundException classNotFound) {
System.out.println(classNotFound.getMessage() + "Error, No se ha encontrado el Driver");
System.exit(1);
}
}
public DefaultTableModel consultarDatos() {
System.out.println("Dentro de consultarDatos");
DefaultTableModel tabla = new DefaultTableModel();
ResultSet resultado = null;
try {
st = con.prepareStatement("SELECT CostoCombId as Clave, CostoCombFecha as Fecha_Costo, CostoCombM3IVA as Costo_con_IVA, CostoCombM3 as Costo_sin_IVA, CostoCombKg as Costo_Kg FROM costocombustoleo;");
resultado = st.executeQuery();
int NumColumn = resultado.getMetaData().getColumnCount();
for (int i = 0; i < NumColumn; i++) {
tabla.addColumn(resultado.getMetaData().getColumnName(i + 1));
}
while (resultado.next()) {
Object[] datos = new Object[NumColumn];
for (int row = 0; row < NumColumn; row++) {
datos[row] = resultado.getObject(row + 1);
}
tabla.addRow(datos);
}
} catch (Exception e) {
e.printStackTrace();
}
return tabla;
}
}
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package visRSJtable2;
import java.sql.*;import javax.swing.table.DefaultTableModel;
/** * * @author Administrador */public class Conexion {
private Connection con; private PreparedStatement st;// private ResultSet resultado;
public Conexion() {
try {
Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pruebadb", "root", "sa");// st = con.prepareStatement("SELECT * FROM tbldatos");// rs1 = st.executeQuery();
} catch (SQLException sqlException) { System.out.println(sqlException.getMessage() + "Error en la Base de Datos"); System.exit(1); } catch (ClassNotFoundException classNotFound) {
System.out.println(classNotFound.getMessage() + "Error, No se ha encontrado el Driver"); System.exit(1); } }
public DefaultTableModel consultarDatos() { System.out.println("Dentro de consultarDatos"); DefaultTableModel tabla = new DefaultTableModel(); ResultSet resultado = null; try { st = con.prepareStatement("SELECT CostoCombId as Clave, CostoCombFecha as Fecha_Costo, CostoCombM3IVA as Costo_con_IVA, CostoCombM3 as Costo_sin_IVA, CostoCombKg as Costo_Kg FROM costocombustoleo;"); resultado = st.executeQuery(); int NumColumn = resultado.getMetaData().getColumnCount(); for (int i = 0; i < NumColumn; i++) { tabla.addColumn(resultado.getMetaData().getColumnName(i + 1)); } while (resultado.next()) { Object[] datos = new Object[NumColumn]; for (int row = 0; row < NumColumn; row++) { datos[row] = resultado.getObject(row + 1); } tabla.addRow(datos); } } catch (Exception e) { e.printStackTrace(); } return tabla; }
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* FrameConsulta.java
*
* Created on 29/07/2010, 08:49:17 AM
*/
package visRSJtable2;
/**
*
* @author Administrador
*/
public class FrameConsulta extends javax.swing.JFrame {
private Conexion obj=null;
/**...
Este es mi codigo:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package visRSJtable2;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Administrador
*/
public class Conexion {
private Connection con;
private PreparedStatement st;
// private ResultSet resultado;
public Conexion() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pruebadb", "root", "sa");
// st = con.prepareStatement("SELECT * FROM tbldatos");
// rs1 = st.executeQuery();
} catch (SQLException sqlException) {
System.out.println(sqlException.getMessage() + "Error en la Base de Datos");
System.exit(1);
} catch (ClassNotFoundException classNotFound) {
System.out.println(classNotFound.getMessage() + "Error, No se ha encontrado el Driver");
System.exit(1);
}
}
public DefaultTableModel consultarDatos() {
System.out.println("Dentro de consultarDatos");
DefaultTableModel tabla = new DefaultTableModel();
ResultSet resultado = null;
try {
st = con.prepareStatement("SELECT CostoCombId as Clave, CostoCombFecha as Fecha_Costo, CostoCombM3IVA as Costo_con_IVA, CostoCombM3 as Costo_sin_IVA, CostoCombKg as Costo_Kg FROM costocombustoleo;");
resultado = st.executeQuery();
int NumColumn = resultado.getMetaData().getColumnCount();
for (int i = 0; i < NumColumn; i++) {
tabla.addColumn(resultado.getMetaData().getColumnName(i + 1));
}
while (resultado.next()) {
Object[] datos = new Object[NumColumn];
for (int row = 0; row < NumColumn; row++) {
datos[row] = resultado.getObject(row + 1);
}
tabla.addRow(datos);
}
} catch (Exception e) {
e.printStackTrace();
}
return tabla;
}
}
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package visRSJtable2;
import java.sql.*;import javax.swing.table.DefaultTableModel;
/** * * @author Administrador */public class Conexion {
private Connection con; private PreparedStatement st;// private ResultSet resultado;
public Conexion() {
try {
Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pruebadb", "root", "sa");// st = con.prepareStatement("SELECT * FROM tbldatos");// rs1 = st.executeQuery();
} catch (SQLException sqlException) { System.out.println(sqlException.getMessage() + "Error en la Base de Datos"); System.exit(1); } catch (ClassNotFoundException classNotFound) {
System.out.println(classNotFound.getMessage() + "Error, No se ha encontrado el Driver"); System.exit(1); } }
public DefaultTableModel consultarDatos() { System.out.println("Dentro de consultarDatos"); DefaultTableModel tabla = new DefaultTableModel(); ResultSet resultado = null; try { st = con.prepareStatement("SELECT CostoCombId as Clave, CostoCombFecha as Fecha_Costo, CostoCombM3IVA as Costo_con_IVA, CostoCombM3 as Costo_sin_IVA, CostoCombKg as Costo_Kg FROM costocombustoleo;"); resultado = st.executeQuery(); int NumColumn = resultado.getMetaData().getColumnCount(); for (int i = 0; i < NumColumn; i++) { tabla.addColumn(resultado.getMetaData().getColumnName(i + 1)); } while (resultado.next()) { Object[] datos = new Object[NumColumn]; for (int row = 0; row < NumColumn; row++) { datos[row] = resultado.getObject(row + 1); } tabla.addRow(datos); } } catch (Exception e) { e.printStackTrace(); } return tabla; }
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* FrameConsulta.java
*
* Created on 29/07/2010, 08:49:17 AM
*/
package visRSJtable2;
/**
*
* @author Administrador
*/
public class FrameConsulta extends javax.swing.JFrame {
private Conexion obj=null;
/**...
1 Respuesta
Respuesta de krlosnow
1