“Cara Menghubungkan Database SQL Dalam Python” Kode Jawaban

Python Cara Terhubung ke SQL Server

import pandas as pd
import pyodbc 

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=RON\SQLEXPRESS;'
                      'Database=test_database;'
                      'Trusted_Connection=yes;')

df = pd.read_sql_query('SELECT * FROM products', conn)

print(df)
print(type(df))
S_Fryer

Cara Menghubungkan Database SQL Dalam Python

#create database in python with mysql

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")
Ruben Visser

Sambungkan ke SQL Database Python

import sqlite3

try:
    sqliteConnection = sqlite3.connect('test.db')
    cursor = sqliteConnection.cursor()
    print("SQLITE Connection Established!")
    cursor.close()

except sqlite3.Error as error:
    print("Error while connecting to sqlite", error)
finally:
    if (sqliteConnection):
        sqliteConnection.close()
        print("Connection closed")
Jerome Scott

SQL Server Python Connection

server = "xx.xxx.x.xxx"
user = "usuario"
password = "1234"
base = "Mi_base_de_datos"
conexion_sql = pymysql.connect(host=server, user=user, passwd=password, db=base)
John

SQL Server Python Connection

//  https://docs.microsoft.com/en-us/sql/connect/python/python-driver-for-sql-server?view=sql-server-ver15 has related information
CompSciGeek

Jawaban yang mirip dengan “Cara Menghubungkan Database SQL Dalam Python”

Pertanyaan yang mirip dengan “Cara Menghubungkan Database SQL Dalam Python”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya