Python 3更新MySQL数据库表(Python 3 Update MySQL database table)
我刚刚找到了用于将Python连接到MySQL数据库的pymysql模块。 我有一个数据库设置了一个名为'loot'的表,loot包含一个名为'wins'的列。 我的代码包含一个名为'won'的变量,它在SQL行之前得到一个值。 我希望将变量'won'输入id = 1的'wins'列。 数据库中已存在id = 1行。
下面的代码抛出错误
pymysql.err.InternalError: (1054, "Unknown column 'won' in 'field list'")
我的问题:为什么我收到此错误以及我做错了什么?
代码:
import pymysql # Open database connection db = pymysql.connect(host='*******',user='******',password='*****',db='******') # prepare a cursor object using cursor() method cursor = db.cursor() won=1 # Prepare SQL query to UPDATE required records sql = "UPDATE loot SET wins = won WHERE id = 1" # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() # disconnect from server db.close()
I have just found the pymysql module for connecting Python to a MySQL database. I have a database set up with a table named 'loot', loot contains a column called 'wins'. My code contains a variable named 'won' that is given a value right before the SQL line. I want the variable 'won' to be entered into the 'wins' column where id=1. The id=1 row already exists in the database.
The code below throws an error
pymysql.err.InternalError: (1054, "Unknown column 'won' in 'field list'")
My Question: Why am I getting this error and what am I doing incorrectly?
The Code:
import pymysql # Open database connection db = pymysql.connect(host='*******',user='******',password='*****',db='******') # prepare a cursor object using cursor() method cursor = db.cursor() won=1 # Prepare SQL query to UPDATE required records sql = "UPDATE loot SET wins = won WHERE id = 1" # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() # disconnect from server db.close()
原文:https://stackoverflow.com/questions/43163196
最满意答案
你有一个
android.os.NetworkOnMainThreadException
,因为你试图从UI线程执行网络操作。 从Android 3.0及更高版本开始,任何从UI线程执行网络操作的尝试都会抛出该异常。解决方案是在单独的线程中运行
generateQrCode()
方法,例如在AsyncTask
或IntentService
。You got a
android.os.NetworkOnMainThreadException
and it's because you are trying to perform network operations from UI thread. Starting with Android 3.0 and higher any attempts to perform network operations from UI thread will throw that exception.The solution is to run
generateQrCode()
method in a separate thread, for example in anAsyncTask
, orIntentService
.
相关问答
更多-
您可以使用手柄设备将位图从图片框中移出 Graphics g = pictureBox1.CreateGraphics(); Bitmap bitMap = Bitmap.FromHbitmap(g.GetHdc()); bitMap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); 或者甚至更好,如果pictureBox不修改图像,则可以直接从pictureBox控件获取图像 pictureBox1.Image.Save ...
-
如何保存qrcode图像?(How can I save a qrcode image?)[2023-09-26]
您可以尝试将其转换为dataURL。 var dataURL = document.getElementById('qrcode').toDataURL(); 然后像这样保存它。 (你可以从js追加这个) 并非所有浏览器都支持此功能。 但现代浏览器会。 You may try converting it into a dataURL. var dataURL = document.getEle ... -
你有一个android.os.NetworkOnMainThreadException ,因为你试图从UI线程执行网络操作。 从Android 3.0及更高版本开始,任何从UI线程执行网络操作的尝试都会抛出该异常。 解决方案是在单独的线程中运行generateQrCode()方法,例如在AsyncTask或IntentService 。 You got a android.os.NetworkOnMainThreadException and it's because you are trying to p ...
-
看看此链接是否对您有所帮助。 本教程还将图像转换为QR码。 I use this code to make QRCODE image QRCodeWriter writer = new QRCodeWriter(); try { BitMatrix bitMatrix = writer.encode(SendQrCode, BarcodeFormat.QR_CODE, 512, 512);//SendQrCode is Want to make ...
-
尝试执行此操作,然后使用数据将其保存在本地设备中。 saveImageBitmap(Bitmap bitmap){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos); byte[] data = baos.toByteArray(); //do whatever you want to save this bitm ...
-
将Google图表保存为PDF(Save google charts as pdf)[2022-03-21]
我们在@cloudformatter中添加了支持,以支持所有Google图表输出为PDF,图像,XPS和其他格式。 你可以看看下面的链接。 Google Charts @cloudformatter支持页面: http ://www.cloudformatter.com/GoogleCharts 整个Javascript的文档: http : //www.cloudformatter.com/CSS2Pdf.APIDoc.Usage 在上面的Google Charts网页中有一些关于实现Handler的提示 ... -
当你运行这个功能 def qr_code_generator(hex_code, username, __show__id, __show__name__, __show__q, price): qr_code_generate_himslef = pyqrcode.create(hex_code) generate_name = ''.join(username + '_' + str(__show__id) + '_' + __show__name__ + '_' + str ...
-
QRlib.php也支持SVG,不是吗? https://github.com/t0k4rt/phpqrcode require_once(__DIR__.'/phpqrcode-master/qrlib.php'); echo QRcode::svg('hello'); QRlib.php also does support SVG, doesn't it? https://github.com/t0k4rt/phpqrcode require_once(__DIR__.'/phpqrcode-mast ...
-
这是他们的错误..结束使用不同的库.. This was bugged with them.. Ended up using a different library..
-
这是一个为您编码的方法。 private void encodeBarcode(String type, String data) { Intent intent = new Intent("com.google.zxing.client.android.ENCODE"); intent.putExtra("ENCODE_TYPE", type); intent.putExtra("ENCODE_DATA", data); startActivity(intent); } 这是一个示例用法 ...