SQL错误或缺少使用sqlite和net bean的数据库(无此表:Employeeinfo) [英] SQL error or missing database(no such table:Employeeinfo) using sqlite and net beans

查看:58
本文介绍了SQL错误或缺少使用sqlite和net bean的数据库(无此表:Employeeinfo)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对我的系统分析和设计课程中的一个项目的,所以我对Java还是很陌生,只是学习了基础课程,而从未学习过数据库.这是我第一次在该网站上发帖,所以我对代码格式有点混乱表示歉意.

This is for a project in my Systems analysis and design class, so i am fairly new to Java, just have taken a basic course, and databases,never taken a course. This is my first time posting on this site, so i apologize if the code format is a little messy.

这是我的班级加载数据库的代码.

Here is the code for my class to load the DB.

import java.sql.*;
import javax.swing.*;
public class javaconnect {
Connection conn=null;

public static Connection ConnecrDB()
{
    try{
        Class.forName("org.sqlite.JDBC").newInstance();
        Connection        conn=DriverManager.getConnection
        ("jdbc:sqlite:Macintosh HD\\Users\\matthewslauson\\Documents\\workspace\\scheduleSystem.sqlite" );
        JOptionPane.showMessageDialog(null, "Connection Successful");
        return conn;
    }catch(Exception e)
        {
        JOptionPane.showMessageDialog(null, e);
            return null;
        }
    }
}

与数据库的连接工作正常,但是当我尝试输入用户名和密码时,才出现错误.这是我的登录屏幕的代码.我向您保证,表Employeeinfo确实存在于scheduleSystem.sqlite中.

The connection to the database works just fine, but it is when i try to input username and password that i get the error. Here is the code for my login screen. I assure you that table Employeeinfo does exist in scheduleSystem.sqlite.

    import java.sql.*;
    import javax.swing.*;

    public class NewJFrame extends javax.swing.JFrame {
    Connection conn=null;
    ResultSet rs =null;
    PreparedStatement pst=null;

/**
 * Creates new form NewJFrame
 */
public NewJFrame() {
    initComponents();
    conn=javaconnect.ConnecrDB();
}

/**
 * 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();
    txtUsername = new javax.swing.JTextField();
    txtPassword = new javax.swing.JPasswordField();
    btnLogin = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    txtUsername.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            txtUsernameActionPerformed(evt);
        }
    });

    txtPassword.setText("jPasswordField1");

    btnLogin.setText("Login");
    btnLogin.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnLoginActionPerformed(evt);
        }
    });

    jLabel1.setFont(new java.awt.Font("Sinhala Sangam MN", 1, 36)); // NOI18N
    jLabel1.setText("Welcome");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(151, 151, 151)
            .addComponent(btnLogin)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap(128, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(128, 128, 128))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel1)
                    .addGap(117, 117, 117))))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(36, 36, 36)
            .addComponent(jLabel1)
            .addGap(32, 32, 32)
            .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(btnLogin)
            .addContainerGap(61, Short.MAX_VALUE))
    );

    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)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

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

private void txtUsernameActionPerformed(java.awt.event.ActionEvent evt) {                                            
    // TODO add your handling code here:
}                                           

private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    String sql ="SELECT * FROM Employeeinfo WHERE uName=? AND pWord=?";
    try{
        pst=conn.prepareStatement(sql);
                    pst.setString(1, txtUsername.getText());
                     pst.setString(2, txtPassword.getText());

                     rs=pst.executeQuery();
                     if(rs.next()){
                         JOptionPane.showMessageDialog(null, "login credentials valid");

                     }
                     else{
                         JOptionPane.showMessageDialog(null, "login credentials invalid");
                     }
    }catch(Exception e)
        {
        JOptionPane.showMessageDialog(null, e);
            JOptionPane.showMessageDialog(null, e);
        }



}                                        

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

// Variables declaration - do not modify                     
private javax.swing.JButton btnLogin;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JTextField txtUsername;
// End of variables declaration                   
}

这是我第一次在该网站上发帖,因此,如果我的代码有点混乱,我深表歉意.

This is my first time posting on this website, so i apologize if my code is a little messy.

推荐答案

我不确定在sqlite中是否类似,但是在Postgresql中,必须在表名前加上模式.例如:schema_name.Employeeinfo

I am not sure if it is similar in sqlite, but in Postgresql, you have to prefix the table name with the schema. Ex: schema_name.Employeeinfo

这篇关于SQL错误或缺少使用sqlite和net bean的数据库(无此表:Employeeinfo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆