Showing posts with label connect mysql. Show all posts
Showing posts with label connect mysql. Show all posts

Friday, February 3, 2017

VBScript MySql connection

You have to install mysql odbc connector first.

Dim Connection, ConnectString

ConnectString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;PORT=3306;Database=database;User=root;Password="

Set Connection = CreateObject("ADODB.Connection")

Connection.Open ConnectString

Sql = "SELECT id,created_at FROM table ORDER BY id DESC LIMIT 0, 10"
Set Result = Connection.Execute(Sql)

Do Until Result.EOF
    Wscript.Echo "Id=" + CStr(Result(0)) + ",Create_Date=" & FormatDateTime(Result(1), 1)
    Result.MoveNext
Loop

Connection.Close

Saturday, July 26, 2014

Quick Guide to Using MySQL in Python

If you are using windows 7 32 bit, then download the python-mysql-connector msi installer and install first.

MySqlPython.py


import MySQLdb
import sys

try :
    db = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="", db="python")
except Exception:
    pass

if db is None:
    print("The database could not connect");
    sys.exit(0)
else:
    print("The database connected");
    cursor = db.cursor();

def executeQuery(query, params = None):
    return cursor.execute(query, params);

def listQuery(query, params = None):
    cursor.execute(query, params);
    return cursor.fetchall();

def readQuery(query, params = None):
    cursor.execute(query, params);
    return cursor.fetchone();

print("Deleting all user from database");
executeQuery("DELETE FROM USER");

print("Inserting user to database...");
query = """Insert into user(name, roll) values(%s, %s)""";
params = ('Pritom', '001');
result = executeQuery(query, params);
print("Insert result: " + str(result));

params = ('Sumon', '002');
result = executeQuery(query, params);
print("Insert result: " + str(result));

params = ('Liton', '003');
result = executeQuery(query, params);
print("Insert result: " + str(result));

print("Reading total user count...");
result = readQuery("SELECT COUNT(*) FROM user");
print("Total user: " + str(result[0]));

print("Reading total user list...");
result = listQuery("SELECT * FROM user");
for row in result:
    print("Id: " + str(row[0]) + ", Name: " + str(row[1]) + ", Roll: " + str(row[2]));

cursor.close();
db.close();   
sys.exit();

Output be as follows:


The database connected
Deleting all user from database
Inserting user to database...
Insert result: 1
Insert result: 1
Insert result: 1
Reading total user count...
Total user: 3
Reading total user list...
Id: 66, Name: Pritom, Roll: 001
Id: 67, Name: Sumon, Roll: 002
Id: 68, Name: Liton, Roll: 003

Monday, September 16, 2013

Getting Started with Grails and MySQL database

Is is so much simple.

Create a file suppose named 'db-config.properties' in 'conf' folder with the following contents:
dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.username = root
dataSource.password =
dataSource.url = jdbc:mysql://localhost/license?useUnicode=yes&characterEncoding=UTF-8
dataSource.dbCreate = update
dataSource.logSql = true
dataSource.insertDummy = true
dataSource.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

/* Your custom class to do some extra work if need */
dataSource.configClass = src.gorm.GormConfiguration;


Where root is your database username.
Where 'license' is your database name.

And make a entry in 'Config.groovy' file under 'conf' folder as following:
grails.config.locations = [ "classpath:db-config.properties" ]

And you need to must do one thing is to download a  java-mysql connector and put it inside lib folder of your project.
Sometimes you need to clean your project to adjust these changes.

You can use more config file like this as:

grails.config.locations =
[
    "classpath:db-config.properties",
    "classpath:some-config.properties" ,
    "file:${userHome}/.grails/${appName}-config.propertis"
]