In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In the Python database connection pool how to create a request connection, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
If you set up connection pooling during the operation of Python database connection pooling, you can do so as follows.
Request connection:
Db = pool.connection ()
You can use these connections just like the original DB-API 2. In fact, a tough connection is used in the ``SteadyDB`` version. Note that connections can be shared with other threads, as long as you set the maxshared parameter to non-zero and the DB-API 2 module allows it. If you want to use a dedicated connection, use:
Db = pool.connection (0)
If you no longer need this connection, you can return it to the connection pool and use db.close (). You can also use the same method to get another connection. Warning: in a multithreaded environment, do not use the following methods:
Pool.connection (). Cursor (). Execute (...) Db = pool.connection () cur = db.cursor () cur.execute (...) Res = cur.fetchone () cur.close () # or del cur db.close () # or del db
Example [convenient for you to use directly in the future]
Use the PersistentDB module
Import threading,time,datetime import MySQLdb import DBUtils.PersistentDB persist = DBUtils.PersistentDB.PersistentDB (MySQLdb,100,host='localhost',user='root',passwd='321',db='test',charset='utf8') conn = persist.connection () cursor = conn.cursor () cursor.execute ("insert into me values (1meme 22222')") conn.commit () conn.close ()
Through the above, you can get the database connection!
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.