SQL
Connect string format: [username]@[hostname]:[port]/[DB service name] [AS SYSDBA] To connect to the first Pluggable Database (PDB) use:
sqlplus sys@localhost:1521/FREEPDB1 as sysdba
To connect to the Container Database (CDB) use:
sqlplus sys@localhost:1521/FREE as sysdba
Java
OracleDataSource ods = new OracleDataSource(); ods.setURL(“jdbc:oracle:thin:@localhost:1521/FREEPDB1”); // jdbc:oracle:thin@[hostname ods.setUser(“[Username]”); ods.setPassword(“[Password]”); Connection conn = ods.getConnection();
PreparedStatement stmt = conn.prepareStatement(“SELECT ‘Hello World!’ FROM dual”); ResultSet rslt = stmt.executeQuery(); while (rslt.next()) { System.out.println(rslt.getString(1)); }
Python
import oracledb
conn = oracledb.connect(user=”[Username]”, password=”[Password]”, dsn=”localhost:1521/ with conn.cursor() as cur:
cur.execute(“SELECT ‘Hello World!’ FROM dual”) res = cur.fetchall() print(res)
Node.js const oracledb = require(‘oracledb’);
async function run() {
let connection = await oracledb.getConnection({ user : “[Username]”, password : “[Password]”, connectString : “localhost:1521/FREEPDB1” // [hostname]:[port]/[DB service name] }); let result = await connection.execute( “SELECT ‘Hello World!’ FROM dual”); console.log(result.rows[0]);
}
run();
C#/.NET
// Connection string format: User Id=[username];Password=[password];Data Source=[hostn OracleConnection con = new OracleConnection(“User Id=[Username];Password=[Password con.Open(); OracleCommand cmd = con.CreateCommand(); cmd.CommandText = “SELECT \’Hello World!\’ FROM dual”;
OracleDataReader reader = cmd.ExecuteReader(); reader.Read(); Console.WriteLine(reader.GetString(0));
PHP
// [username], [password], [hostname]:[port]/[DB service name] $c = oci_pconnect(“[Username]”, “[Password]”, “localhost:1521/FREEPDB1”); $s = oci_parse($c, “SELECT ‘Hello World!’ FROM dual”); oci_execute($s); oci_fetch_all($s, $res); echo “<pre>\n” var_dump($res); echo “</pre>\n”;
Ruby
require ‘oci8’
con = OCI8.new(“[Username]”, “[Password]”, “localhost:1521/FREEPDB1”) statement = “SELECT ‘Hello World!’ FROM dual” cursor = con.parse(statement) cursor.exec cursor.fetch do |row| print row end
Go
package main
import ( “fmt” “log” “database/sql” _ “github.com/godror/godror” )
func main() {
// connectString format: [hostname]:[port]/[DB service name]
dsn := `user=”[Username]”
password=”[Password]”
connectString=”localhost:1521/FREEPDB1″`
db, err := sql.Open(“godror”, dsn) if err != nil { panic(err) } defer db.Close()
rows, err := db.Query(“SELECT ‘Hello World!’ FROM dual”) if err != nil { panic(err) } defer rows.Close()
var strVal string for rows.Next() {
err := rows.Scan(&strVal)
if err != nil {
log.Fatal(err)
}
fmt.Println(strVal) } err = rows.Err() if err != nil {
log.Fatal(err) }
}
downlaod oracle 23c Get Started with Oracle Database 23c | Oracle
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/310601.html