-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqldbaccess.py
More file actions
28 lines (24 loc) · 805 Bytes
/
Copy pathmysqldbaccess.py
File metadata and controls
28 lines (24 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This script connects to a MySQL DB
# Copyright (C) 2017 Ana Cruz-Martín (anacruzmartin@gmail.com)
import sys
import os
from gvsig import *
from gvsig import geom
from gvsig.geom import *
from java.util import Properties
sys.path.append(“/pathtomygvSIGfolder/mysql-connector-java-5.1.40-bin.jar”);
import org.gjt.mm.mysql.Driver as Driver
def main():
# Connect to the database
props = Properties()
props.put(“user”,”myuser”)
props.put(“password”,”mypasswd”)
db = Driver().connect(“jdbc:mysql://localhost/mydb”, props)
# Get geometry info from database and insert it into the new layer
c = db.createStatement()
rs = c.executeQuery(“select * from mytable where somecolumn=’somevalue'”)
while rs.next():
id = rs.getString(“somecolumn”)
rs.close()
c.close()
db.close()