python更新数据库
㈠ 如何通过python程序知道mssql数据库是否更新了
通过python程序知道mssql数据库是否更新,要实现这样一个功能,使用python连接sqlserver数据库,并返回当前数据库时间。
import os,pymssql
server="192.186.1.26\nwork"
user="np"
password="np.123"
conn=pymssql.connect(server,user,password,database="master")
cursor=conn.cursor()
cursor.execute("""select getdate()""")
row=cursor.fetchone()
while row:
print("sqlserver version:%s"%(row[0]))
row=cursor.fetchone()
conn.close()
㈡ 如何用python更新oracle数据库
用python更新oracle数据库:
1. 要想使Python可以操作Oracle数据库,首先需要安装cx_Oracle包,可以通过下面的地址来获取安装包:cx-oracle.sourceforge.net/
2. 另外还需要oracle的一些类库,此时需要在运行python的机器上安装Oracle Instant Client软件包,可以通过下面地址获得technetwork/database/features/instant-client/index-097480.html
找到符合自己平台的包,然后安装,这里我使用的是rpm包,所以使用以下命令安装
$ sudo rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
装完毕后还需要设置一下环境变量,如下
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/oracle/11.2/client/lib
然后写update语句对表进行更新:
import cx_Oracle //导入链接oracle的库
conn = cx_Oracle.connect('fkong/[email protected]/orcl') //建立与orcl的连接
cursor = conn.cursor () //打开游标
cursor.execute ("update test set COL1='u' where ID=1") //执行更新
conn.commit() //提交结果
cursor.close (); //关闭游标
conn.close ();//关闭连接
㈢ python数据库更新操作求助
importMySQLdb
#主机名
HOST='127.0.0.1'
#用户名
USER="root"
#密码
PASSWD="123456"
#数据库名
DB="db_name"
#打开数据库连接
db=MySQLdb.connect(HOST,USER,PASSWD,DB)
#获取操作游标
cursor=db.cursor()
if__name__=='__main__':
ifcursor:
command_a="updatetables_onesetstatus=5wherestatus=0"
#使用execute方法执行SQL语句
cursor.execute(command_a)
#提交到数据库执行
db.commit()
command2="selectfieldfromtables_onewhereid=12"
ret2=cursor.execute(command2)
#获取所有记录列表
ret2=cursor.fetchall()
foriteminret2:
command3="insertintotables_two(name)values(%s);"%(item[0])
fin=cursor.execute(command3)
db.commit()
#关闭数据库连接
db.close()
㈣ python连接MYSQL数据库,调用update语句后无法更新数据,求大神解决
sql_Update="updateomssm.t_securitylogsetDATETIME=0whereSN=%s;"
curA.execute(sql_Update,[Str_Sn,])
conn.commit()#在update之後加个commit试试
㈤ update更新数据库 python
这样试试
sql = "update staff_everymonth_overtimes set Jan=%s,Feb=%s where id=1" %('Jan','Feb')
㈥ 如何用python更新mysql数据库数据
mysql> show databases; // 查看当前所有的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| csvt |
| csvt04 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.18 sec)
mysql> use test; //作用与test数据库
Database changed
mysql> show tables; //查看test库下面的表
Empty set (0.00 sec)
//创建user表,name 和password 两个字段
mysql> CREATE TABLE user (name VARCHAR(20),password VARCHAR(20)); Query OK, 0 rows affected (0.27 sec)
//向user表内插入若干条数据
mysql> insert into user values('Tom','1321');
Query OK, 1 row affected (0.05 sec)
mysql> insert into user values('Alen','7875');
Query OK, 1 row affected (0.08 sec)
mysql> insert into user values('Jack','7455');
Query OK, 1 row affected (0.04 sec)
//查看user表的数据
mysql> select * from user;
+------+----------+
| name | password |
+------+----------+
| Tom | 1321 |
| Alen | 7875 |
| Jack | 7455 |
+------+----------+
3 rows in set (0.01 sec)
//删除name 等于Jack的数据
mysql> delete from user where name = 'Jack';
Query OK, 1 rows affected (0.06 sec)
//修改name等于Alen 的password 为 1111
mysql> update user set password='1111' where name = 'Alen';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
//查看表内容
mysql> select * from user;
+--------+----------+
| name | password |
+--------+----------+
| Tom | 1321 |
| Alen | 1111 |
+--------+----------+
3 rows in set (0.00 sec)
㈦ python update动态数据到mysql
sql="UPDATE USER SET dataaddress=dataadd, datauser=datauser, datapw=datapw, databa=datapw WHERE username='zhaop'"
这样试试
㈧ python 更新数据库语句问题
你后面的port的字段类型是文本或字符串型的吧。在等号后面是不是需要加上双引号或单引号叱?
㈨ Python的mysql数据库的更新如何实现
conn本来 就已经被你定义成了 函数, conn.ping()当然不存在了。而且你要的数据库连接c,还被手动关回闭了答。我觉得有两点 1. 按照你这个脚本的情况,你用一次,就新建一个数据库连接问题应该不大。 2. 要保持使用一个连接的话。把c作全局变量 c=MyS...