Jump to content
  • 0

Conection DataBase aCis


Question

Posted

hello wanted result because i can not adapt to l2jacis

 


    
    @SuppressWarnings("resource")
    private void addOfflineItem(int owner_id, int item_id, int count){
        // owner_id , object_id, item_id, count, enchant_lv, loc
        String SQL_INSERT = "INSERT INTO items VALUES (?, ?, ?, ?, 0, 'INVENTORY', 0, 0, 0, NULL, 0, 0, -1)";
        String SQL_MAX = "SELECT MAX(object_id) as objid FROM items";
        String SQL_VERIFY_EXISTS = "SELECT count FROM items WHERE item_id = ? and owner_id = ?";
        String UPDATE_ITEM = "UPDATE items SET count = ? WHERE owner_id = ? and item_id = ? ";
        Connection con1 = null, con2 = null, con3 = null, con4 = null;
        ResultSet rs;
        PreparedStatement st;
        try
        {

            con1 = L2DatabaseFactory.getInstance().getConnection();
            st = con1.prepareStatement(SQL_VERIFY_EXISTS);
            st.setInt(1,item_id);
            st.setInt(2,owner_id);
            rs = st.executeQuery();
            int total = 0;
            
            while (rs.next())
            {
                total = rs.getInt("count");
            }
            
            st.close();
            rs.close();

            
            con2 = L2DatabaseFactory.getInstance().getConnection();
            st = con2.prepareStatement(SQL_MAX);
            st.executeQuery();
            rs = st.executeQuery();
            
            int obj_id = 0;
            
            while (rs.next())
            {
                obj_id = rs.getInt("objid") + 1000;
            }
            
            st.close();
            rs.close();
            
            
            
            if(total == 0){
                con3 = L2DatabaseFactory.getInstance().getConnection();
                st = con3.prepareStatement(SQL_INSERT);
                st.setLong(1,owner_id);
                st.setLong(2,obj_id);
                st.setInt(3,item_id);
                st.setInt(4, count);
                st.execute();
                st.close();
            
            }else{
                con4 = L2DatabaseFactory.getInstance().getConnection();
                st = con4.prepareStatement(UPDATE_ITEM);
                st.setInt(1, total + count);
                st.setLong(2, owner_id);
                st.setLong(3, item_id);
                st.execute();
                st.close();

            }
            
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }finally{
            if (con1 != null)
                CloseUtil.close(con1);
            if (con2 != null)
                CloseUtil.close(con2);
            if (con3 != null)
                CloseUtil.close(con3);
            if (con4 != null)
                CloseUtil.close(con4);
        }
    }

1 answer to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..