Holas a todos estaba buscando informacion en internet para poder conectar SQL Server 2000 con NetBeans 6.0 y este foro me convencio. Bueno estamos realizando un primer proyecto de un mantenedor simple lo pueden ver en el video:
http://www.youtube.com/results?searc...rch_type=&aq=f
ya hicimos todo lo que esta en el video pero nuestro gran problema es conectarlo con el SQL Server 2000; seguimos una guia bajada del net lo pueden ver ahi:
http://usuarios.lycos.es/manualesjav...ases_datos.pdf
en el que conectaba el SQL Server 2000 con el MySql y si logre hacerlo y pensamos que seria similar para el SQL Server 2000; lo intente hasta el cansancio pero no dio resultados por favor si me podrian ayudar es un trabajo de la universidad urgenteeeeeeeeeeeeeeeeeee...
muchas gracias de antemano...
espero sus respuestas...
PD: el video tiene autor io solo lo estoy copiando pero aun asi o puedo.
-----Agregado el 21/10/2009 a las 06 : 07 : 56----- ahh les dejo el codigo para que tengan una idea mas clara: este codigo es del FrmMantenedorAlumno:
package biblioteca;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.lang.*;
public class FrmMantenedorAlumno extends javax.swing.JFrame
{
Object[][] filas=null;
String cod=null;
// private Connection ocn = null;
public FrmMantenedorAlumno()
{
initComponents();
//cargarData();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jchbhabilitado = new javax.swing.JCheckBox();
jtxtnombres = new javax.swing.JTextField();
jtxtapellidos = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jtxtdireccion = new javax.swing.JTextArea();
jftxttelefono = new javax.swing.JFormattedTextField();
jcmbdistrito = new javax.swing.JComboBox();
jcmbsexo = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
agregar = new javax.swing.JButton();
guardar = new javax.swing.JButton();
modificar = new javax.swing.JButton();
eliminar = new javax.swing.JButton();
salir = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.create TitledBorder("Datos del Alumno"));
jLabel2.setText("Nombre");
jLabel3.setText("Apellido");
jLabel4.setText("Direccion");
jLabel5.setText("telefono");
jLabel6.setText("Distrito");
jLabel7.setText("Sexo");
jchbhabilitado.setText("¿se encuentra habilitado?");
jchbhabilitado.setHorizontalTextPosition(javax.swi ng.SwingConstants.LEFT);
jtxtdireccion.setColumns(20);
jtxtdireccion.setRows(5);
jScrollPane2.setViewportView(jtxtdireccion);
try {
jftxttelefono.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("044} ##-##-##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jtxtnombres, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
.addComponent(jtxtapellidos)))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jcmbdistrito, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jftxttelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jchbhabilitado)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(20, 20, 20)
.addComponent(jcmbsexo, 0, 186, Short.MAX_VALUE)))))
.addGap(31, 31, 31))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jLabel2)
.addComponent(jtxtnombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jftxttelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jLabel3)
.addComponent(jtxtapellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jcmbdistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(13, 13, 13)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7)
.addComponent(jcmbsexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addComponent(jchbhabilitado))
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(18, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"Codigo", "Apellido", "Nombre", "Direccion", "Telefono", "Distrito", "Sexo", "Habilitado"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
};
boolean[] canEdit = new boolean [] {
true, true, true, true, false, true, true, true
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
agregar.setText("Agregar");
agregar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
agregarMouseClicked(evt);
}
});
guardar.setText("Guardar");
guardar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
guardarMouseClicked(evt);
}
});
modificar.setText("Modificar");
modificar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
modificarMouseClicked(evt);
}
});
eliminar.setText("Eliminar");
eliminar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
eliminarMouseClicked(evt);
}
});
salir.setText("Salir");
salir.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
salirMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addGap(16, 16, 16)
.addComponent(agregar)
.addGap(54, 54, 54)
.addComponent(guardar)
.addGap(53, 53, 53)
.addComponent(modificar)
.addGap(51, 51, 51)
.addComponent(eliminar)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 63, Short.MAX_VALUE)
.addComponent(salir, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(11, 11, 11))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(agregar)
.addComponent(guardar)
.addComponent(modificar)
.addComponent(eliminar)
.addComponent(salir))
.addGap(28, 28, 28)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21))
);
pack();
}// </editor-fold>
private void formWindowOpened(java.awt.event.WindowEvent evt) {
JOptionPane mensaje=new JOptionPane();
Connection ocn=null;
Statement consulta=null;
ResultSet lector=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://CRISTHIAN:1433; databasename=Biblioteca", "sa", "sa");
consulta=ocn.createStatement(ResultSet.TYPE_SCROLL _SENSITIVE, ResultSet.CONCUR_READ_ONLY);
lector=consulta.executeQuery("select codusuario from alumnos order by ASC");
while(lector.next())
{
this.jcmbdistrito.addItem(lector.getString(1));
}
this.jcmbsexo.addItem("MASCULINO");
this.jcmbsexo.addItem("FEMENINO");
this.cargarData();
lector.close();
ocn.close();
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
}
private void agregarMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
Alumno objeto=new Alumno();
objeto.setNombres(this.jtxtnombres.getText());
objeto.setApellidos(this.jtxtapellidos.getText());
objeto.setDireccion(this.jtxtdireccion.getText());
objeto.setDistrito(this.jcmbdistrito.getSelectedIt em().toString());
if(this.jcmbsexo.getSelectedItem().toString().comp areTo("MASCULINO")==0)
{
objeto.setSexo("M");
}
else
{
objeto.setSexo("F");
}
objeto.setTelefono(this.jftxttelefono.getText());
objeto.setHabilitado(this.jchbhabilitado.isSelecte d());
this.insertarRegistro(objeto);
this.limpiar(); this.cargarData();
}
private void guardarMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
Alumno objeto=new Alumno();
objeto.setNombres(this.jtxtnombres.getText());
objeto.setApellidos(this.jtxtapellidos.getText());
objeto.setDireccion(this.jtxtdireccion.getText());
objeto.setDistrito(this.jcmbdistrito.getSelectedIt em().toString());
if(this.jcmbsexo.getSelectedItem().toString().comp areTo("MASCULINO")==0)
{
objeto.setSexo("M");
}
else
{
objeto.setSexo("F");
}
objeto.setTelefono(this.jftxttelefono.getText());
objeto.setHabilitado(this.jchbhabilitado.isSelecte d());
this.actualizarRegistro(objeto, Integer.parseInt(cod));
this.limpiar(); this.cargarData();
}
private void modificarMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
cod=filas[this.jTable1.getSelectedRow()][0].toString();
this.jtxtnombres.setText(filas[this.jTable1.getSelectedRow()][1].toString());
this.jtxtapellidos.setText(filas[this.jTable1.getSelectedRow()][2].toString());
this.jtxtdireccion.setText(filas[this.jTable1.getSelectedRow()][3].toString());
this.jftxttelefono.setText(filas[this.jTable1.getSelectedRow()][4].toString());
this.jcmbdistrito.setSelectedItem(filas[this.jTable1.getSelectedRow()][5].toString());
this.jcmbsexo.setSelectedItem(filas[this.jTable1.getSelectedRow()][6].toString());
this.jchbhabilitado.setSelected(Boolean.parseBoole an(filas[this.jTable1.getSelectedRow()][7].toString()));
}
private void eliminarMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.eliminarRegistro(Integer.parseInt(cod));
this.limpiar();
this.cargarData();
}
private void salirMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
//************************************************** ************************
// METODO PARA LIMPIAR LOS CONTROLES
//************************************************** ************************
private void limpiar()
{
this.jtxtnombres.setText("");
this.jtxtdireccion.setText("");
this.jtxtapellidos.setText("");
this.jftxttelefono.setText("");
this.jcmbdistrito.setSelectedIndex(0);
this.jcmbsexo.setSelectedIndex(0);
this.jchbhabilitado.setSelected(false);
}
//************************************************** ************************
// METODO PARA ELIMINAR REGISTRO
//************************************************** ************************
private void eliminarRegistro(int codigo)
{
Connection ocn=null;
JOptionPane mensaje=new JOptionPane();
Statement consulta=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://CRISTHIAN; databasename=Biblioteca", "sa", "sa");
consulta=ocn.createStatement(ResultSet.TYPE_SCROLL _SENSITIVE, ResultSet.CONCUR_UPDATABLE);
consulta.executeUpdate("delete from alumnos where codusuario=" + codigo);
mensaje.showMessageDialog(this, "El alumno se elimino de la Base de Datos", "Sistema Biblioteca",JOptionPane.INFORMATION_MESSAGE);
ocn.close();
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
}
private void actualizarRegistro(Alumno objeto, int codigo)
{
Connection ocn=null;
JOptionPane mensaje=new JOptionPane();
Statement consulta=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://CRISTHIAN; databasename=Biblioteca", "sa", "sa");
consulta=ocn.createStatement(ResultSet.TYPE_SCROLL _SENSITIVE, ResultSet.CONCUR_UPDATABLE);
consulta.executeUpdate("update alumnos set nombres='" + objeto.getNombres() + "',apellidos='" + objeto.getApellidos() + "',direccion='" + objeto.getDireccion() + "',phono='" + objeto.getTelefono() + "',coddistrito=" + objeto.buscarCodigo() + ",sexo='" + objeto.getSexo() + "',habilitado=" + (objeto.isHabilitado()?1:0) + " where codusuario=" + codigo);
mensaje.showMessageDialog(this, "El alumno " + objeto.getApellidos().trim().toUpperCase() + ", " + objeto.getNombres().trim().toUpperCase() + " se actualizo correctamente", "Sistema Biblioteca",JOptionPane.INFORMATION_MESSAGE);
ocn.close();
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
}
private void insertarRegistro(Alumno objeto)
{
Connection ocn=null;
JOptionPane mensaje=new JOptionPane();
Statement consulta=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://CRISTHIAN; databasename=Biblioteca", "sa", "sa");
consulta=ocn.createStatement(ResultSet.TYPE_SCROLL _SENSITIVE, ResultSet.CONCUR_UPDATABLE);
consulta.executeUpdate("insert into alumnos(nombres,apellidos,direccion,phono,coddistr ito,sexo,habilitado) " + "values('" + objeto.getNombres() + "','" + objeto.getApellidos() + "','" + objeto.getDireccion() + "','" + objeto.getTelefono() + "'," + objeto.buscarCodigo() + ",'" + objeto.getSexo() + "'," + (objeto.isHabilitado()?1:0) + ")");
mensaje.showMessageDialog(this, "El alumno " + objeto.getApellidos().trim().toUpperCase() + ", " + objeto.getNombres().trim().toUpperCase() + " se registro correctamente", "Sistema Biblioteca",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
}
private void cargarData()
{
JOptionPane mensaje=new JOptionPane();
Connection ocn=null;
Statement consulta1=null;
Statement consulta2=null;
ResultSet lector=null;
ResultSet cantfilas=null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(this, "El controlador no cargo correctamente", "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://CRISTHIAN; databasename=Biblioteca", "sa", "sa");
consulta2=ocn.createStatement(ResultSet.TYPE_SCROL L_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
consulta1=ocn.createStatement(ResultSet.TYPE_SCROL L_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
lector=null;
lector=consulta2.executeQuery("select codusuario, nombres, apellidos, direccion, phono, d.distrito, " + "case when sexo='F' then 'FEMENINO' else 'MASCULINO' end as sexo, habilitado " + "from dbo.Alumnos a inner join distritos d on a.coddistrito=d.coddistrito");
cantfilas=consulta1.executeQuery("select count(*) from alumnos");
cantfilas.next();
Object[] columnas={"Codigos","Nombres","Apellidos","Direcci ón","Teléfono","Distrito","Sexo","Habilitado"};
filas=new Object[cantfilas.getInt(1)+1][8];
int c=0;
int i=0;
while(lector.next())
{
filas[i][0]="" + lector.getInt(1);
filas[i][1]="" + lector.getString(2);
filas[i][2]="" + lector.getString(3);
filas[i][3]="" + lector.getString(4);
filas[i][4]="" + lector.getString(5);
filas[i][5]="" + lector.getString(6);
filas[i][6]="" + lector.getString(7);
filas[i][7]="" + lector.getBoolean(8);
i++;
}
DefaultTableModel mydata=new DefaultTableModel(filas,columnas);
this.jTable1.setModel(mydata);
this.jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_ ALL_COLUMNS);
this.jtxtdireccion.setLineWrap(true);
lector.close();
ocn.close();
}
catch(Exception err)
{
mensaje.showMessageDialog(this, err.getMessage(), "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new FrmMantenedorAlumno().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton agregar;
private javax.swing.JButton eliminar;
private javax.swing.JButton guardar;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JCheckBox jchbhabilitado;
private javax.swing.JComboBox jcmbdistrito;
private javax.swing.JComboBox jcmbsexo;
private javax.swing.JFormattedTextField jftxttelefono;
private javax.swing.JTextField jtxtapellidos;
private javax.swing.JTextArea jtxtdireccion;
private javax.swing.JTextField jtxtnombres;
private javax.swing.JButton modificar;
private javax.swing.JButton salir;
// End of variables declaration
}
y este es de la clase Alumno:
package biblioteca;
import java.sql.*;
import javax.swing.*;
public class Alumno
{
private int codigo;
private String nombres;
private String apellidos;
private String direccion;
private String telefono;
private int coddistrito;
private String sexo;
private boolean habilitado;
private String _distrito;
public Alumno()
{
codigo=0;
nombres="";
apellidos="";
direccion="";
telefono="";
coddistrito=0;
sexo="";
habilitado=false;
}
public Alumno(String nombre, String apellido, String _direccion,String phono,int codditri, String sex, boolean habilit )
{
codigo=0;
nombres=nombre;
apellidos=apellido;
direccion=_direccion;
telefono=phono;
coddistrito=codditri;
sexo=sex;
habilitado=habilit;
}
public int buscarCodigo()
{
JOptionPane mensaje=new JOptionPane();
Connection ocn=null;
Statement consulta1=null;
ResultSet lector=null;
int resp=-1;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
}
catch(Exception err)
{
mensaje.showMessageDialog(null, "El controlador no cargo correctamente", "Sistema de Biblioteca", JOptionPane.ERROR_MESSAGE);
}
try
{
ocn=DriverManager.getConnection("jdbc:sqlserver://casa; databasename=Biblioteca", "sa", "cp246725");
consulta1=ocn.createStatement(ResultSet.TYPE_SCROL L_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
lector=consulta1.executeQuery("select coddistrito from distritos where distrito='" + _distrito + "'");
lector.next();
if(lector==null)
{
resp=-1;
}
else
{
resp=Integer.parseInt(lector.getString(1));
}
lector.close();
ocn.close();
}
catch(Exception err)
{
mensaje.showMessageDialog(null, "Error al tratar de buscar el codigo", "Sistema Biblioteca", JOptionPane.ERROR_MESSAGE);
}
return resp;
}
public void setDistrito(String distrito)
{
_distrito=distrito;
}
public String getDistrito()
{
return _distrito;
}
public String getApellidos()
{
return apellidos;
}
public void setApellidos(String apellidos)
{
this.apellidos = apellidos;
}
public int getCoddistrito()
{
return coddistrito;
}
public void setCoddistrito(int coddistrito)
{
this.coddistrito = coddistrito;
}
public int getCodigo()
{
return codigo;
}
public void setCodigo(int codigo)
{
this.codigo = codigo;
}
public String getDireccion()
{
return direccion;
}
public void setDireccion(String direccion)
{
this.direccion = direccion;
}
public boolean isHabilitado()
{
return habilitado;
}
public void setHabilitado(boolean habilitado)
{
this.habilitado = habilitado;
}
public String getNombres()
{
return nombres;
}
public void setNombres(String nombres)
{
this.nombres = nombres;
}
public String getSexo()
{
return sexo;
}
public void setSexo(String sexo)
{
this.sexo = sexo;
}
public String getTelefono()
{
return telefono;
}
public void setTelefono(String telefono)
{
this.telefono = telefono;
}
}
espero su ayuda muy pronto gracias de antemano