View manipulating-data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
View exampleCheckObjectType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(pointA instanceof Coordinate) | |
System.out.println("type Coordinate"); |
View Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Employee extends Person { | |
//... | |
} |
View ExampleMainCoordinate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
View ExampleMainPerson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
View Coordinate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
View Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
//attributes | |
private String name; | |
private Date dateBirth; | |
//methods | |
public void walk(){ ... } | |
public void talk(){ ... } |
View connect.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
View connect02.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mysql.connector import (connection) | |
db_connection = connection.MySQLConnection(host='127.0.0.1', user='root', password='', database='bd') | |
db_connection.close() |
View query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |