Dotnet,php,java Database Connection code Daquan (with demo code)

Source: Internet
Author: User
Tags dotnet dsn sqlite sqlite database connectionstrings

C # Database connection string

Web. config file

  <connectionStrings>    <!--SQL Server database connection -    <Addname= "Conn_sqlserver"connectionString= "Server=;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=; 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=, 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,, version=, 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=;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=,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=,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=;port=5432//PDO connection to Oracle DSN string (need to open "extension=php_pdo_oci.dll" option in PHP config file)Oci:dbname=//

Download: [Pdo_dns_demo (PDO connects to various database demos). zip]

PHP official DSN Description:
For more information on DSN connection strings, refer to:

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:
This article Sochishun (e-mail: | blog:
Published: July 3, 2017

Dotnet,php,java Database Connection code Daquan (with demo code)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.