DotNet 连SQLServer:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
DbConnection _Conn;
public static void func()
{
DbConnection _Conn =new SqlConnection(@"Data Source=10.133.72.43\TEST;Initial Catalog=ElecTagdb;Persist Security Info=True;User ID=haq;Password=sa");
if (_Conn != null && _Conn.State != ConnectionState.Open)
{
try
{
_Conn.Open();
Console.Write("suc");
_Conn.Close();
}
catch (Exception e)
{
Console.Write(e.Message);
}
}
}
static void Main(string[] args)
{
func();
Console.Read();
}
}
}
Java建立Oracle连接:
public static Connection getCommonConnection() throws Exception {
Connection connection = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl,"用户名","密码");
} catch (Exception e) {
e.printStackTrace();
throw new QMLMPException(e);
}
return connection;
}