Jump to content

Question

Posted

could this remove? I'm adapting a frozen code for now and would like to know if removing this would give some error

 

finally
        {
            try
            {
                con.close();
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
            con = null;
        }

9 answers to this question

Recommended Posts

  • 0
Posted

connections must be closed . otherwise Ressource leak will take place and MySQLNonTransientConnectionException  error will appear because of unclosed ressource

  • 0
Posted
1 hour ago, SweeTs said:

Ye, remove that and use connection inside the loop. Look sources, tons of examples. 

 

but the loop would send to the gs, right? in case if any player change password will go to the gs by what I saw in that code there the exit is null

 

     
+    private void updPassKey(L2PcInstance player, String pass)
+    {
+        Connection con = null;
+        String query = "UPDATE passkey SET passkey = ? WHERE obj_Id = ?";
+        try
+        {
+            con = L2DatabaseFactory.getInstance().getConnection();
+            PreparedStatement st = con.prepareStatement(query);
+            st.setString(1, encodePass(pass));
+            st.setInt(2, player.getObjectId());
+            st.executeUpdate();
+            st.close();
+            st = null;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        finally
+        {
+            try
+            {
+                con.close();
+            }
+            catch (SQLException e)
+            {
+                e.printStackTrace();
+            }
+            con = null;
+        }
+    }
+    

  • 0
Posted (edited)
try (Connection con = L2DatabaseFactory.getInstance().getConnection())
{
	PreparedStatement st = con.prepareStatement("UPDATE passkey SET passkey = ? WHERE obj_Id = ?");
	st.setString(1, encodePass(pass));
    st.setInt(2, player.getObjectId());
    st.executeUpdate();
    st.close();
}
catch (Exception e)
{
	 e.printStackTrace();
}

 

Simply use try-with-ressources statements, then java automatically will close the connection

 

Edit: Your error has nothing to do with the connection btw

Edited by melron
  • 0
Posted
30 minutes ago, melron said:

try (Connection con = L2DatabaseFactory.getInstance().getConnection())
{
	PreparedStatement st = con.prepareStatement("UPDATE passkey SET passkey = ? WHERE obj_Id = ?");
	st.setString(1, encodePass(pass));
    st.setInt(2, player.getObjectId());
    st.executeUpdate();
    st.close();
}
catch (Exception e)
{
	 e.printStackTrace();
}

 

Simply use try-with-ressources statements, then java automatically will close the connection

 

Edit: Your error has nothing to do with the connection btw

 

the error is here because when I change the password of this error

+            else if (_command.equalsIgnoreCase("pkrecovery"))
+           {
+                String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+                NpcHtmlMessage html = new NpcHtmlMessage(1);
+                html.setHtml(htmContent);
+                html.replace("%question%", getPassKeyQuestion(activeChar));
+                activeChar.sendPacket(html);
+                html = null;
+           }
+            else if (_command.startsWith("pkset"))
+            {
+                StringTokenizer st = new StringTokenizer(_command, "]");
+            if (st.countTokens() != 5)
+                {
+                    activeChar.sendMessage("You have not entered all the data!");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                String newCommand = st.nextToken();
+                String pass1 = st.nextToken();
+                pass1 = pass1.substring(1, pass1.length() - 1);
+                String pass2 = st.nextToken();
+                pass2 = pass2.substring(1, pass2.length() - 1);
+                String question = st.nextToken();
+                question = question.substring(1, question.length() - 1);
+                String answer = st.nextToken();
+                answer = answer.substring(1, answer.length());
+                if (pass1 == null || pass2 == null || question == null || answer == null)
+                {
+                    activeChar.sendMessage("Input error");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                
+                if (!pass1.equals(pass2))
+                {
+                    activeChar.sendMessage("You entered different passwords");
+                    activeChar.sendMessage("pass1 = " + pass1);
+                    activeChar.sendMessage("pass2 = " + pass2);
+                    activeChar.sendMessage("Question = " + question);
+                    activeChar.sendMessage("answer = " + answer);
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                insertPassKeyInformation(activeChar, pass1, question, answer);
+                String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+                NpcHtmlMessage html = new NpcHtmlMessage(1);
+                html.setHtml(htmContent);
+                activeChar.sendPacket(html);
+                html = null;
+            }
+            else if (_command.startsWith("pklogin"))
+            {
+                StringTokenizer st = new StringTokenizer(_command, " ");
+                if (st.countTokens() != 2)
+                {
+                    activeChar.sendMessage("You make a mistake when entering the password!");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                String newCommand = st.nextToken();
+                String pass = st.nextToken();
+                Connection con = null;
+                String query = "SELECT passkey FROM passkey WHERE obj_Id = ?";
+                String pwdindb = "error";
+                try
+                {
+                con = L2DatabaseFactory.getInstance().getConnection();
+                PreparedStatement ps = con.prepareStatement(query);
+                ps.setInt(1, activeChar.getObjectId());
+                ResultSet rs = ps.executeQuery();
+                    
+                while (rs.next())
+                    pwdindb = rs.getString(1);
+                    rs.close();
+                    ps.close();
+                    ps = null;
+                    rs = null;
+                }
+                catch (Exception e)
+                {
+                e.printStackTrace();
+                }
+                finally
+                {
+                    try
+                    {
+                        con.close();
+                    }
+                    catch (SQLException e)
+                    {
+                        e.printStackTrace();
+                    }
+                    con = null;
+                }
+                if (pwdindb.equals(encodePass(pass)))
+                {
+                    activeChar.setIsParalyzed(false);
+                    activeChar.setIsSubmitingPin(false);
+                    activeChar.setIsInvul(false);
+                }
+                else
+                {
+                    activeChar.sendMessage("You have not entered the correct password");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+            }
+            else if (_command.startsWith("pkrec"))
+            {
+                StringTokenizer st = new StringTokenizer(_command, " ");
+                if (st.countTokens() != 4)
+                {
+                    activeChar.sendMessage("You make a mistake when entering data!");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    html.replace("%question%", getPassKeyQuestion(activeChar));
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                String newCommand = st.nextToken();
+                String answer = st.nextToken();
+                String pass1 = st.nextToken();
+                String pass2 = st.nextToken();
+                if (!pass1.equals(pass2))
+                {
+                    activeChar.sendMessage("You entered different passwords");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    html.replace("%question%", getPassKeyQuestion(activeChar));
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+                Connection con = null;
+                String query = "SELECT answer FROM passkey WHERE obj_Id = ?";
+                  String anwindb = "error";
+                try
+                {
+                    con = L2DatabaseFactory.getInstance().getConnection();
+                    PreparedStatement ps = con.prepareStatement(query);
+                    ps.setInt(1, activeChar.getObjectId());
+                    ResultSet rs = ps.executeQuery();
+                    
+                    while (rs.next())
+                        anwindb = rs.getString(1);
+                    
+                    rs.close();
+                    ps.close();
+                    ps = null;
+                    rs = null;
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+                finally
+                {
+                    try
+                    {
+                        con.close();
+                    }
+                    catch (SQLException e)
+                    {
+                        e.printStackTrace();
+                    }
+                    con = null;
+                }
+                
+                if (anwindb.equals(answer))
+                {
+                    updPassKey(activeChar, pass1);
+                    activeChar.sendMessage("You have successfully changed your password.");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    activeChar.sendPacket(html);
+                    html = null;
+                }
+                else
+                {
+                    activeChar.sendMessage("You entered the wrong answer to your question");
+                    String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+                    NpcHtmlMessage html = new NpcHtmlMessage(1);
+                    html.setHtml(htmContent);
+                    html.replace("%question%", getPassKeyQuestion(activeChar));
+                    activeChar.sendPacket(html);
+                    html = null;
+                    return;
+                }
+            }

  • 0
Posted

Its obvious that is there (RequestBypassToServer) but not in mysql connection. Debug your code and find your line

  • 0
Posted

Many thanks to both of you I have re-created the code and removed the garbage and updated the closing method you mentioned

2 hours ago, melron said:

Its obvious that is there (RequestBypassToServer) but not in mysql connection. Debug your code and find your line

 

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


  • Posts

    • I was looking for  server with a low rates,eventually i found l2 elixir.I Joined beta and after so many years since 2008 i found  a friend that we played together, memories came back. i cant wait for the grand oppening!. dont miss it!
    • Seems legit, for sure deserves a try!
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
    • SOCNET VERIFICATION SERVICE — is a universal solution for those who value security, convenience, and quality. We turn the verification process into a convenient, fast, and highly confidential experience. Thanks to our service, any of your accounts receive identity confirmation, an increased level of trust from platforms and users, as well as protection from bans, fraud, and risks.   Promotion: Pay for your first verification and get a 10% discount on the second one! 💎 We help with verification on Fragment, crypto exchanges ByBit, Gate, Bitget, OKX, Binance, PayPal, KuCoin, and social networks LinkedIn, Facebook, Instagram, Twitter (X) and many other platforms! 💎 Verification for any service: crypto exchanges, trading platforms, hosting providers, casinos and other websites. Why choose us:   Premium quality — we use the most advanced verification methods. High processing speed — accelerated verification on leading platforms, online services and social networks. Full confidentiality — your personal information is protected. Increased trust and status — a verified account boosts influence and improves conversion. Individual approach — we work with bloggers, brands, businesses, and private clients. Simplifying complexity — we handle issues when dealing with foreign services. Important! Services related to illegal activities are strictly prohibited! 💳 Service pricing   ✅ Verification of individuals — from $30 (the exact cost depends on the required location and service/app/website). Learn more 👨‍💼 The cost of business verification for companies or legal entities is discussed individually with the service administration. Learn more If you want us to register your account on the required service and verify it — you will need to additionally pay 10% of the transaction amount. Available payment methods: cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot.   ⭐ Our Online Store ⭐ SOCNET.STORE ⭐ Telegram Store ⭐ SOCNET.SHOP ⭐ Our SMS Service ⭐ SOCNET.APP ⭐ Our Telegram Bot for buying Telegram Stars ⭐ SOCNET.CC ⭐ Our SMM Panel ⭐ SOCNET.PRO   ✅ News Resources ➡ Telegram Channel ➡ WhatsApp Channel ➡ Discord Server     ⭐ We invite you to COOPERATE and EARN with us ⭐ Would you like to sell your product or service in our stores and earn money? Become our partner or offer mutually beneficial collaboration? You can contact us via the CONTACTS listed in this topic. ✅ Contacts & Support ➡ Telegram Support ➡ WhatsApp Support ➡ Discord Support: socnet_support ➡ Email Support: solomonbog@socnet.store   Terms of Use and Refund Policy If you have any questions or issues, our fast support service is ready to respond to your requests! A refund for a completed service that does not fully meet the requirements or the declared quality is possible only if the product description includes a warranty and a valid warranty period. In other cases, a full refund for the service will not be provided! By purchasing such a service, you automatically agree to our refund rules for non-provided services! Refunds for countries selected by mistake are not provided after verification. To complete verification, you must provide full access to your account. We currently accept cryptocurrency, credit cards, PayPal, and other payment methods in our online store and Telegram bot! We value every client and provide replacements in case of invalid accounts via our contact channels! Attention: Your order will be delivered to your personal Google Drive/Mega.nz via a link (check the link, click “View content”) within 24 hours after the order confirmation! If you purchased more than 1 item at once, your entire order will be delivered via the first link! The remaining links will be empty! You will automatically receive an email notification after delivery! If you pay on our website via PayPal, you must pay an additional 20% commission (minimum $1). To avoid this commission, you can pay me directly via PayPal — instructions are available on the website! Refunds for items purchased by mistake or due to “I chose the wrong product and did not use it” are not accepted! You are fully responsible for your actions before and after purchase.
    • +8? Isnt +5 max per one stat?
  • Topics

×
×
  • 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