Sunday, April 24, 2016

GO with MYSQL

GO's default SQL package is database/sql, and it allows more generalized database connectivity. In this post, I'm going to use third party mysql driver called Go-MySQL-Driver. You can install it using following command.
Then we need to create a database schema for this. I'll use student table schema like below.
Create GO project using Eclipse. Then add Student struct like below.
Then we need to import required packages.
And also in the main function I have connected to my mysql database. In the connection string you have to give mysql database, username and password appropriately.
Following image show how to write the CreateStudent function.
Next I have wrote GetStudent function.
You can invoke above functions from the main function like below.

No comments:

Post a Comment