Кнопка выбора в моем коде не работает и выдает ошибку исключения
"Excepnet.ucanaccess.jdbc.UcanaccessSQLException: UCAExc ::: 4.0.4 недопустимое состояние курсора: курсор идентификатора не расположен настрока в выражении UPDATE, DELETE, SET или GET:; ResultSet располагается перед первой строкой "` import javax.swing.JOptionPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author HP
*/
public class dbgui extends javax.swing.JFrame {
/**
* Creates new form
*/
public dbgui() {
initComponents();
}
/**
* 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() {
jMenuItem1 = new javax.swing.JMenuItem();
txtRollNo = new javax.swing.JTextField();
txtName = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
insertbtn = new javax.swing.JButton();
updatebtn = new javax.swing.JButton();
deletebtn1 = new javax.swing.JButton();
selectbtn = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
txtid = new javax.swing.JTextField();
jMenuItem1.setText("jMenuItem1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
txtRollNo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtRollNoActionPerformed(evt);
}
});
txtName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNameActionPerformed(evt);
}
});
jLabel1.setText("Enter Name");
jLabel2.setText("Enter Roll no");
insertbtn.setText("Insert");
insertbtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
insertbtnActionPerformed(evt);
}
});
updatebtn.setText("Update");
updatebtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
updatebtnActionPerformed(evt);
}
});
deletebtn1.setText("Delete");
deletebtn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deletebtn1ActionPerformed(evt);
}
});
selectbtn.setText("Select");
selectbtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectbtnActionPerformed(evt);
}
});
jLabel3.setText("Student ID");
txtid.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtidActionPerformed(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.TRAILING, layout.createSequentialGroup()
.addGap(61, 61, 61)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(selectbtn)
.addComponent(insertbtn))
.addGroup(layout.createSequentialGroup()
.addGap(2, 2, 2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtRollNo, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(updatebtn)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(110, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(192, Short.MAX_VALUE)
.addComponent(deletebtn1)
.addGap(149, 149, 149)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtRollNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
.addComponent(insertbtn)
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(updatebtn)
.addComponent(selectbtn))
.addGap(72, 72, 72))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(146, Short.MAX_VALUE)
.addComponent(deletebtn1)
.addGap(131, 131, 131)))
);
pack();
}// </editor-fold>
private void txtRollNoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void insertbtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
dbstd s1= new dbstd(txtName.getText(),txtRollNo.getText(),txtid.getText());
if( s1.addSTudent()>0)
{
JOptionPane.showMessageDialog(null,"Record Inserted Successfully");
}
}
catch(Exception ex)
{
System.out.println("Excep"+ex);
JOptionPane.showMessageDialog(null,ex);
}
}
private void updatebtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
dbstd s1= new dbstd(txtName.getText(),txtRollNo.getText(),txtid.getText());
if(s1.updstudent()>0)
{
JOptionPane.showMessageDialog(null,"Record Updated Successfully");
}
}
catch(Exception ex)
{
System.out.println("Excep"+ex);
JOptionPane.showMessageDialog(null,ex);
}
}
private void deletebtn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
dbstd s1= new dbstd(txtName.getText(),txtRollNo.getText(),txtid.getText());
if(s1.delstudent()>0)
{
JOptionPane.showMessageDialog(null,"Record Deleted Successfully");
}
}
catch(Exception ex)
{
System.out.println("Excep"+ex);
JOptionPane.showMessageDialog(null,ex);
}
}
private void selectbtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
dbstd s1= new dbstd(txtName.getText(),txtRollNo.getText(),txtid.getText());
dbconn dbcon=new dbconn();
String qry ="SELECT * FROM tbl ";
while(dbcon.Rs(qry).next())
{
System.out.println("STUDENT_ID"+dbcon.Rs(qry).getString(1)+"\t STD_ROLLNO"+dbcon.Rs(qry).getString(2)+"\t STD_NAME"+dbcon.Rs(qry).getString(3));
}
}
catch(Exception ex)
{
System.out.println("Excep"+ex);
JOptionPane.showMessageDialog(null,ex);
}
}
private void txtidActionPerformed(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(dbgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(dbgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(dbgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(dbgui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new dbgui().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton deletebtn1;
private javax.swing.JButton insertbtn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JButton selectbtn;
private javax.swing.JTextField txtName;
private javax.swing.JTextField txtRollNo;
private javax.swing.JTextField txtid;
private javax.swing.JButton updatebtn;
// End of variables declaration
}
import javax.swing.JOptionPane;
import java.sql.*;
import java.sql.ResultSet;
/* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author HP
*/
public class dbconn {
String url="jdbc:ucanaccess://D:\\database.accdb";
Connection conn;
Statement st;
public dbconn(){
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
conn=DriverManager.getConnection(url);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,ex);
}
}
public int udi(String qry){
try{
st=conn.createStatement();
return st.executeUpdate(qry);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,ex);
System.out.println(ex+"EX");
return -1;
}
}
public ResultSet Rs(String qry)
{
try{
st= conn.createStatement();
return st.executeQuery(qry);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,ex);
return null;
}
}
}