色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

mysql數據庫連接技術

林玟書2年前11瀏覽0評論

MySQL是目前比較流行的關系型數據庫,支持多種編程語言對其進行訪問和操作。本文將介紹MySQL的幾種連接技術。

1. JDBC連接

import java.sql.*;
public class MySQLDemo {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/test_db?useSSL=false";
String user = "root";
String password = "123456";
try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM user");
while (rs.next()) {
System.out.println(rs.getString("username") + "," + rs.getString("password"));
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

2. PHP連接

0) {
while($row = mysqli_fetch_assoc($result)) {
echo "username: " . $row["username"]. ", password: " . $row["password"]. "
"; } } else { echo "0 results"; } mysqli_close($conn); ?>

3. Python連接

import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="123456",
database="test_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM user")
myresult = mycursor.fetchall()
for x in myresult:
print(x)
mydb.close()

以上為MySQL的幾種連接技術,開發者可以根據自己的需求和熟練程度選擇合適的連接方式。