C # Database connection string
Web. config file
<connectionStrings> <!--SQL Server database connection - <Addname= "Conn_sqlserver"connectionString= "Server=127.0.0.1;uid=testuser;pwd=testpwd;database=db_test;pooling=true;min pool Size=10;max pool size=1024; Connection Lifetime=300;packet size=1000 "ProviderName= "System.Data.SqlClient"/> <!--MySQL Database connection - <Addname= "Conn_mysql"connectionString= "Data source=127.0.0.1; Database=db_test; User Id=testuser; Password=testpwd; Pooling=false; Charset=utf8; port=3306 "ProviderName= "MySql.Data.MySqlClient"/> <!--SQLite Database Connection - <Addname= "Conn_sqlite"connectionString= "Data source=| DATADIRECTORY|\DB_TEST.DB3; Pooling=true; Failifmissing=false "ProviderName= "System.Data.SQLite" /> </connectionStrings> <!--fix Dbproviderfactories.getfactory (ProviderName) Exception: "The requested. Net Framework Data Provider cannot be found. may not be installed. " - <System.Data> <dbproviderfactories> <Removeinvariant= "System.Data.SQLite"/> <Addname= "SQLite Data Provider"invariant= "System.Data.SQLite"Description= ". Net Framework Data Provider for SQLite"type= "System.Data.SQLite.SQLiteFactory, System.Data.SQLite, version=1.0.105.2, Culture=neutral, publickeytoken= db937bc2d44ff139 " /> <Removeinvariant= "MySQL Data Provider"/> <Addname= "MySQL Data Provider"invariant= "MySql.Data.MySqlClient"Description= ". Net Framework Data Provider for MySQL"type= "MySql.Data.MySqlClient.MySqlClientFactory, Mysql.data, version=6.9.9.0, Culture=neutral, publickeytoken= C5687fc88969c44d " /> </dbproviderfactories> </System.Data>
Download: Csharpdbconnectiondemo (dotnet database connection demo). zip
Java Database connection string
//MySQLDriver= "Com.mysql.jdbc.Driver"; URL= "Jdbc:mysql://localhost:3306/db_test?useunicode=true&characterencoding=utf8"; Conn= Getconnection (Driver,url, "User", "password"); System.out.println ("Connect with MySQL database" + (NULL= = conn? "Failed": "Success"));//SQLiteDriver= "Sqlite.jdbcdriver"; URL= "JDBC:SQLITE:/C:/DB_TEST.DB3"; Conn=getconnection (Driver,url); System.out.println ("Connect with SQLite database" + (NULL= = conn? "Failed": "Success"));//SQL ServerDriver= "Com.mysql.jdbc.Driver"; URL= "Jdbc:sqlserver://localhost:1433;databasename=db_test"; Conn= Getconnection (Driver,url, "User", "password"); System.out.println ("Connect with SQL Server database" + (NULL= = conn? "Failed": "Success"));//OracleDriver= "Oracle.jdbc.driver.OracleDriver"; URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"; Conn= Getconnection (Driver,url, "User", "password"); System.out.println ("Connect with Oracle Database" + (NULL= = conn? "Failure": "Success");
JDBC Connection Database method
Public Static Connection getconnection (string driver, string URL, string user, string password) { null; try { // Initialize driver package class.forname (driver); = drivermanager.getconnection (url, user, password); Catch (Exception e) { e.printstacktrace (); } return Conn;}
Download: [Jdbc_connection_demo (JDBC connection to various database demos). zip]
Php_pdo Database Connection string
//PDO connection MySQL DSN string (need to open "extension=php_pdo_mysql.dll" option in PHP config file)MySQL:d bname=db_test;host=127.0.0.1;port=3306;charset=UTF8//PDO connection to SQLite DSN string (need to open "extension=php_pdo_sqlite.dll" option in PHP config file)sqlite:test_db.db3//PDO connects SQL Server DSN strings via ODBC (requires opening the "extension=php_pdo_odbc.dll" option in the PHP configuration file)Odbc:driver={sql Server}; Server=127.0.0.1,1433;database=db_test;//PDO connects the DSN string for SQL Server (configuration is cumbersome and is recommended in ODBC mode.) PHP5.3.6 above version of Php_mssql.dll,php_pdo_mssql.dll have disappeared, only a php_pdo_odbc.dll, so the latest and best PHP connection MSSQL method should be the use of ODBC driver mode. )Sqlsrv:database=db_test; server=127.0.0.1,1433//PDO connection to PostgreSQL DSN string (need to open "extension=php_pdo_pgsql.dll" option in PHP config file)pgsql:dbname=db_test;host=127.0.0.1;port=5432//PDO connection to Oracle DSN string (need to open "extension=php_pdo_oci.dll" option in PHP config file)Oci:dbname=//127.0.0.1:5432/db_test
Download: [Pdo_dns_demo (PDO connects to various database demos). zip]
PHP official DSN Description: http://php.net/manual/en/ref.pdo-odbc.connection.php
For more information on DSN connection strings, refer to: http://www.connectionstrings.com/
Copyright NOTICE: This document is licensed under the attribution-Non-commercial use-sharing (CC BY-NC-SA 3.0 CN) International License Agreement, please specify the author and source. This article title: Dotnet,php,java's Database Connection code Daquan (with demo code) This article link: http://www.cnblogs.com/sochishun/p/7113193.html This article Sochishun (e-mail: 14507247#qq.com | blog: http://www.cnblogs.com/sochishun/) Published: July 3, 2017 |
Dotnet,php,java Database Connection code Daquan (with demo code)