如何使用python从树莓派向Oracle SQL数据库插入行? [英] How can I insert rows into Oracle SQL databse from a raspberry pi using python?

查看:290
本文介绍了如何使用python从树莓派向Oracle SQL数据库插入行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个个人项目,其中涉及:

I'm currently working on a personal project which involves:


  • 带有RFID读写器模块的Raspberry Pi Model b

  • Oracle SQL数据库(11g)

  • Python脚本

这是我要执行的操作:
我需要Raspberry Pi发送从RFID标签读取的UID(唯一标识号),并在其中插入一行到我的SQL数据库中UID。从RFID标签读取的信息是一堆数字,可以存储为字符串。

Here's what I'm trying to-do: I need the Raspberry Pi to send the UID (unique identification number) which I've read from the RFID tag and insert a row into my SQL database with the UID. The information read from the RFID tag is a bunch of numbers which can be stored as a String.

我目前能够读取标签并将UID打印到屏幕上。我正在从网上找到的源代码修改过的Python脚本正在处理该读数。

I am currently able to read tags and print the UID onto the screen. The reading is being processed by a Python script which I've modified from a source code I found online.

我正在努力将UID发送到SQL数据库。我研究了cx_Oracle,但似乎Raspberry Pi使用的ARM体系结构中不存在它。我也研究了pyodbc,但似乎也无法正常工作。这是我用来读取RFID标签的Python脚本。

I am struggling to send the UID to my SQL database. I have looked into cx_Oracle but it seems that it doesn't exist for the ARM Architecture which the Raspberry Pi uses. I have also looked into pyodbc but I can't seem to get that working either. Here is my Python script which I am using to read the RFID tags.

其他信息
:我是菜鸟谈到Python,我有C,Java,JDBC和Oracle SQL的背景。我了解JDBC连接的工作原理,但似乎无法在Python中实现相同的理论。对于任何Python专业人士来说,请随时在下面修改我的代码以访问Oracle SQL数据库。我数据库的凭据如下:

Extra Info : I am a noob when it comes to Python, I have a background in C, Java, JDBC and Oracle SQL. I understand how JDBC connections work but I can't seem to implement the same theory in Python. To anyone that is a pro at Python, please feel free to modify my code below to access an Oracle SQL database. The credentials to my database is as follows:


  • 地址:localhost

  • 端口:1521

  • 用户:学生

  • 密码:测试

  • 方案:学生

  • 表名称:EMP

  • Address: localhost
  • Port: 1521
  • User: student
  • Password: test
  • Scheme: STUDENT
  • Table Name: EMP

#!/usr/bin/env python
# -*- coding: utf8 -*-

import RPi.GPIO as GPIO
import MFRC522
import signal
continue_reading = True

# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()

# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:

# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"

# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()

# If we have the UID, continue
if status == MIFAREReader.MI_OK:

# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])


推荐答案

要访问oracle数据库,则需要Rpi上的客户端库。

To access an oracle database then you need client libraries on the Rpi.

您似乎已经发现,这些不存在

As you seem to have discovered already, these don't exist for the ARM Linux architecture, and certainly not for the Raspian O/S.

您可以考虑将ODBC驱动程序用于RPi,看看是否可以使它工作

You could look into using an ODBC driver for RPi to see if you can get this to work.

此帖子显示了有人已经尝试过此操作。

This Post shows what somebody has tried this already.

我还发现了这篇文章,声称已经通过PHP在Rpi上完成了这项工作。他所使用的驱动程序的公司(与他合作)也有一个python驱动程序。
但是,请访问他们的网站该软件是商业软件(可免费试用),并不声称支持ARM Linux。虽然您可以尝试免费试用。

And I also found this article, where somebody claims to have gotten this working for Rpi via PHP. The company who's driver he used (which he works for) also have a python driver. However, looking on their website the software is commercial (free trial available) and does not claim to support ARM Linux. Although you could try with their free trial.

这里是其他可用的python驱动程序的ODBC驱动程序列表。

Here is a list of other ODBC drivers which have python drivers available.

尽管我从未尝试过,也没有在该领域的经验,公开SOAP Web服务的方法oracle数据库。因此,您可以尝试使用他的方法,以便DB公开服务,然后从python访问Web服务。但是由于我还没有这样做,所以我不知道任何限制,或者它是否真的适合您。

Although I have never tried it or have experience in this area, there is a way to expose SOAP web services from the oracle database. So you could try his approach instead, so the DB exposes the services and then you access the web service from python. But as I have not done it I don't know about any limitation or if this would actually work for you.

否则,您将需要采用其他方法,并且在Rpi和DB之间使用某种中间件来接收数据并将其插入。
或使用其他数据库!

Otherwise, you would need to take a different approach and use some kind of middle ware between the Rpi and the DB to receive the data and insert it. Or use another database!

这篇关于如何使用python从树莓派向Oracle SQL数据库插入行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆