Jump to content
  • 0

Conection DataBase aCis


l2jkain

Question

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);
        }
    }

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock