
java连接数据库:
import java.sql.*
class Jdbc_dml
{
public static void main(String[] args)throws SQLException,ClassNotFoundException
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
String url = "jdbc:sqlserver://127.0.0.1:1433DatabaseName=kk"
Connection conn = DriverManager.getConnection(url,"sa","107613")
Statement stmt = conn.createStatement()
}
//127.0.0.1:1433是本地IP,kk数据库名,sa用sqlserver混合登陆,107613密码名;
C#连接数据库:
using System
using System.Collections.Generic
using System.Text
using System.Data
using System.Data.SqlClient
namespace TransactionTest
{
class Program
{
static void Main(string[] args)
{
string conn = "Data Source =(local)Initial Catalog=FlightIntegrated Security=SSPI"
RunSqlTransaction(conn)
}
private static void RunSqlTransaction(string myConnString)
{
SqlConnection myConnection = new SqlConnection(myConnString)
myConnection.Open()
SqlCommand myCommand = myConnection.CreateCommand()
SqlTransaction myTrans
//开始一个事务
myTrans = myConnection.BeginTransaction()
//必须同时指定事务和连接对象给Command对象
myCommand.Connection = myConnection
myCommand.Transaction = myTrans
//利用Try...Catch...finally结构
try
{
myCommand.CommandText = "insert into Region(RegionID,RegionDescription)values(100,'Description')"
myCommand.ExecuteNonQuery()
myCommand.CommandText = "insert into Region(RegionID,RegionDescription)values(ssss,'Description')"
myCommand.ExecuteNonQuery()
myTrans.Commit()//执行成功则提交
Console.WriteLine("两条记录添加成功")
}
catch (Exception e)
{
try
{
myTrans.Rollback()
}
catch (SqlException ex)
{
if (myTrans.Connection != null)
{
Console.WriteLine("在执行事务的回滚过程中出现错误代码为: " + ex.GetType() + "的错误")
}
}
Console.WriteLine("在添加数据过程中出现错误代号为:" + e.GetType() + "的错误")
Console.WriteLine("没有数据添加到数据中")
}
finally
{
myConnection.Close()
}
}
}
}
部门表数据
左连接 left join 表示A表和B表的公共部分,再加上A表的独有部分。
右连接right join 表示A表和B表公共部分,在加上B表的独有部分。
查找A表独有部分,则需查找A表和B表的共有部分并加上A表的独有部分,在将A表和B表的共有部分剔除即可(也就是挑选B的主键为空的数据)。
查找B表独有部分,则需查找A表和B表的共有部分并加上B表的独有部分,在将A表和B表的共有部分剔除即可(也就是挑选A的主键为空的数据)。
全连接则表示将A表和B表的公共部分及A表、B表的独有部分,所有数据都查询出来
指导图的全连接 full outer join 在mysql 语法报错!但是可以通过union关键字进行查询。
UNION会把 重复的行去掉,返回的行都是唯一的。如果想保留重复行,可以使用 UNION ALL 关键字。
UNION其实就是将A表和B表的共有部分及A表的独有部分(即左连接left join)加上A、B表共有部分及B表的独有部分(即右连接right join)合并起来,并进行去重即可。
查询A表独有部分并加上B表独有部分
实际就是查询A表的独有部分和B表的独有部分,使用UNION进行连接即可。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)