Files
Feeding_control_system/Flag.py
2025-10-28 19:51:36 +08:00

37 lines
912 B
Python

import pyodbc
# 数据库连接信息
db_path = "D:\\Janeoo-B12-DB\\Janeoo.2.mdb" # 替换为实际路径
password = "BCS7.2_SDBS" # Access数据库密码
def get_unique_flags_from_access(db_path, password):
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
f'DBQ={db_path};'
f'PWD={password};'
)
try:
# 连接数据库
conn = pyodbc.connect(conn_str)
cursor = conn.cursor()
# 查询所有Flag字段的值
cursor.execute("SELECT DISTINCT Flag FROM Produce")
flags = cursor.fetchall()
# 输出结果
print("唯一的Flag值:")
for flag in flags:
print(flag[0]) # flag[0]是查询结果中的第一个字段
conn.close()
except Exception as e:
print(f"数据库操作失败: {e}")
# 调用函数
get_unique_flags_from_access(db_path, password)