Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不应使用java和mysql将现有的Empno添加到数据库中_Java - Fatal编程技术网

不应使用java和mysql将现有的Empno添加到数据库中

不应使用java和mysql将现有的Empno添加到数据库中,java,Java,我正在创建一个简单的员工工资系统休假部分。我在为员工添加休假信息时遇到问题。所有休假信息将添加在公司工作的所有员工。当新员工到来时,如果我为新员工添加假期信息,那么假期信息也会再次添加到现有员工中。我只需要添加新员工的假期信息如何执行任务。现有记录不会再次添加 员工表 离开桌子 这是我尝试的代码,但没有错误,但不起作用 String cas = txtcas.getValue().toString(); String anu = txtanu.getValue().toStr

我正在创建一个简单的员工工资系统休假部分。我在为员工添加休假信息时遇到问题。所有休假信息将添加在公司工作的所有员工。当新员工到来时,如果我为新员工添加假期信息,那么假期信息也会再次添加到现有员工中。我只需要添加新员工的假期信息如何执行任务。现有记录不会再次添加

员工表

离开桌子

这是我尝试的代码,但没有错误,但不起作用

 String cas = txtcas.getValue().toString();
         String anu = txtanu.getValue().toString();
         String med = txtmed.getValue().toString();
         String year = txtyear.getText();

        try {
            int c;
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/spay","root","");
           PreparedStatement pst1 = con.prepareStatement("select empno from registation");
            ResultSet rs = pst1.executeQuery();
             String empNoValue1 = rs.getString("empno");
            PreparedStatement pst2 = con.prepareStatement("select empno from leaves");  
            String empNoValue = rs.getString("empno");
            ResultSet rs1 = pst2.executeQuery();

            while (rs.next()) {

                if(rs1.next())

                {
                    if(empNoValue1.equals(empNoValue))
                    {

                    }



                }
                else
                {

                pst = con.prepareStatement("insert into leaves(empno,casual,annual,medical,year)values(?,?,?,?,?)");
                pst.setString(1,empNoValue); // employee no how to give 
                pst.setString(2, cas);
                pst.setString(3, anu);
                pst.setString(4, med);
                pst.setString(5, year);         
                pst.executeUpdate();
                }



           }    
                JOptionPane.showMessageDialog(null,"Leave Insertedddddd");

如果我理解正确,您希望增加一些工人的ID值

    Connection con = null;
    Statement stmt = null;
    int id = 0;

    try {
        Class.forName("org.postgresql.Driver");
        con = DriverManager.getConnection("url", "username", "pwd");
        con.setAutoCommit(true);
        stmt = con.createStatement();

        ResultSet rs = stmt.executeQuery("SELECT id FROM userlist ORDER BY id DESC LIMIT 1");

        while (rs.next()) {
            id = rs.getInt("id");
        }

        id++;
        stmt.execute("INSERT INTO userlist (id) VALUES (" + String.valueOf(id) + ");");
    } catch (Exception e) {
        e.printStackTrace();
    }
我使用了postgresql,所以您必须稍微更改查询。其原理是获取具有最高ID的工作者,将ID增加1,然后用其他数据重写新ID


我希望我能帮助您

员工否自动否-我就是这样使用ES001的。我尝试了你的代码,它显示了java.sql.SQLException的错误:getInt-'ES001'的值无效,然后尝试getStringyour table name或'ES001'是什么类型的,并创建一个函数来增加这个值,这些是postgresql命令,因此你可以稍微更改它们