Skip to content

Instantly share code, notes, and snippets.

View mayararysia's full-sized avatar
👋
Hello!

Mayara Rysia mayararysia

👋
Hello!
View GitHub Profile
@mayararysia
mayararysia / connect02.py
Created September 4, 2019 15:49
File that connects to the MySQL database
from mysql.connector import (connection)
db_connection = connection.MySQLConnection(host='127.0.0.1', user='root', password='', database='bd')
db_connection.close()
@mayararysia
mayararysia / Person.java
Last active August 20, 2020 21:26
An example of a class Person
public class Person {
//attributes
private String name;
private Date dateBirth;
//methods
public void walk(){ ... }
public void talk(){ ... }
@mayararysia
mayararysia / Coordinate.java
Created August 21, 2020 14:44
An example of a class Coordinate
import java.lang.Math;
public class Coordinate {
// attributes
private Double x;
private Double y;
// constructor
// defined how to create an instance of this class
public Coordinate(Double x, Double y) {
this.x = x;
@mayararysia
mayararysia / ExampleMainPerson.java
Created August 21, 2020 14:58
An example of a class Main - Person
class Main {
public static void main(String[] args) {
// person1 object is of type Person
Person person1 = new Person();
person1.setName("Teddy");
person1.walk(); // person1 walks
// person2 object is of type Person
Person person2 = new Person();
@mayararysia
mayararysia / ExampleMainCoordinate.java
Last active August 21, 2020 15:09
An example of a class Main
class Main {
public static void main(String[] args) {
Coordinate pointA = new Coordinate(5.0, 6.0); // (5,6) pointA object is of type Coordinate
Coordinate origin = new Coordinate(0.0, 0.0); // (0,0) origin object is of type Coordinate
System.out.println("abscissa - point A> x: " + pointA.getX() ); // abscissa - point A: 5
System.out.println("abscissa - origin> x: " + origin.getX() ); // abscissa - origin: 0
System.out.println("-- Distance: "+ pointA.distance(origin) ); //result: 7.81
}
}
@mayararysia
mayararysia / Employee.java
Created August 21, 2020 16:53
Example of indication of inheritance
public class Employee extends Person {
//...
}
if(pointA instanceof Coordinate)
System.out.println("type Coordinate");
@mayararysia
mayararysia / manipulating-data.py
Last active September 8, 2020 07:15
Manipulating Data Using Connector / Python
from datetime import date
import mysql.connector
db_connection = mysql.connector.connect(host="localhost", user="root", passwd="", database="bd")
cursor = db_connection.cursor()
sql = "INSERT INTO user (name, cpf) VALUES (%s, %s)"
values = ("Maria", "025.658.698-55")
cursor.execute(sql, values)
current_date = date.today()
formatted_date = current_date.strftime('%d/%m/%Y')
@mayararysia
mayararysia / query.sql
Last active July 23, 2023 11:54
Example query for mysql connection exercise
create database bd;
use bd;
CREATE TABLE `user` (
`id` SERIAL PRIMARY KEY,
`name` VARCHAR(30) NOT NULL,
`cpf` VARCHAR(20) NOT NULL
);
INSERT INTO `user` (`name`, `cpf`) VALUES ('Leta Lestrange', '012.236.987-44'), ('Newt Scamander', '021.545.258-55'),
('Hermione Granger', '024.547.658-77');
@mayararysia
mayararysia / connect.py
Last active October 6, 2023 12:32
File that connects to the MySQL database
import mysql.connector
from mysql.connector import errorcode
try:
db_connection = mysql.connector.connect(host='localhost', user='root', password='', database='bd')
print("Database connection made!")
except mysql.connector.Error as error:
if error.errno == errorcode.ER_BAD_DB_ERROR:
print("Database doesn't exist")
elif error.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("User name or password is wrong")