我尝试为我的swing应用程序插入数据库中的数据,但显示错误


  java.sql.SQLException:无法检索过程的元数据。


at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.CallableStatement.extractProcedureName(CallableStatement.java:861)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:692)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:513)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4536)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4610)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4584)
at ttg.subject.saveActionPerformed(subject.java:110)
at ttg.subject.access$000(subject.java:15)
at ttg.subject$1.actionPerformed(subject.java:72)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6535)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6300)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4891)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4713)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


我的代码在这里:

   /*
    * 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.
  */
 package ttg;

import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
*
* @author Chirag Gojaria
*/


公共类主题扩展了javax.swing.JFrame {

database db = new database();

/**
 * Creates new form subject
 */
public subject() {
    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() {

    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    nhr = new javax.swing.JTextField();
    name = new javax.swing.JTextField();
    cradit = new javax.swing.JTextField();
    save = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
    jLabel1.setText(":: Subject ::");
    jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(352, 46, 102, 29));

    jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    jLabel3.setText("Name                   :");
    jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 90, 130, 30));

    jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    jLabel4.setText("Cradit                  :");
    jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 130, 120, 30));

    jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    jLabel5.setText("No. of Hourse Req :");
    jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 180, 130, 30));
    jPanel1.add(nhr, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 180, 240, 30));
    jPanel1.add(name, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 90, 240, 30));
    jPanel1.add(cradit, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 130, 240, 30));

    save.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    save.setText("Save");
    save.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveActionPerformed(evt);
        }
    });
    jPanel1.add(save, new org.netbeans.lib.awtextra.AbsoluteConstraints(483, 233, 100, 30));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
            .addGap(28, 28, 28))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
            .addGap(31, 31, 31))
    );

    pack();
}// </editor-fold>

private void saveActionPerformed(java.awt.event.ActionEvent evt) {

    try {
        db.connection();
        if (name.getText().length() > 0) {

            ResultSet rs = db.getSpecificRecord("subject", "name", name.getText());

            if (rs.next()) {

                JOptionPane.showMessageDialog(this, "Alredy entered", "Error", JOptionPane.ERROR_MESSAGE);

            } else {
                java.sql.PreparedStatement psb = db.cn.prepareCall("insert into subject values(?,?,?)");
                psb.setString(1, name.getText());
                psb.setString(2, cradit.getText());
                psb.setString(3, nhr.getText());
                psb.execute();
                db.cn.close();
                JOptionPane.showMessageDialog(this, "New User create Successfully", "success", 1);

            }

        }

    } catch (Exception e) {

        e.printStackTrace();

    }
}

/**
 * @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(subject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(subject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(subject.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(subject.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 subject().setVisible(true);
        }
    });
}

// Variables declaration - do not modify
private javax.swing.JTextField cradit;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField name;
private javax.swing.JTextField nhr;
private javax.swing.JButton save;
// End of variables declaration


}

请给一些建议

最佳答案

您正在尝试使用prepareCall()(用于调用存储过程)执行常规SQL查询。请改用prepareStatement()

10-07 19:24
查看更多