菜鸟笔记 ADO vs JDBC

菜鸟笔记 ADO vs JDBC

ADO
produce connection

1.variable declaration: String
connectionString;
SqlConnection cnn;
2.set connection string:connectionString=""
3.assign connection:cnn=new SqlConnection(connectionString)
4.open connection:cnn.open
message.show(“connection open”)
5.close connection:cnn.close

reading data records from database

1.define variable:
SqlCommend commend;
Sqldatareader datareader
String sql, output=""
2.define sql statement:
sql=“Select TutorialID,TutoriaName from demotb”;
3.the commend statement:
commend =new SqlCommend(sql,cnn)
4.define the data reader:
dataReader=commend.ExcuteReader()
5.get the table values:
while (dataReader.Reader())
{
output=output+dataReader.GetValue(0)+"-"
+dataReader.GetValue(1)+"\n";
}

insert data records into database

1.define variables:
SqlCommend commend;
SqlDataAdapter adapter=new SqlDataAdapter();
2.define the insert statement:
Sql=“insert into demotb (TutorialID,TutorialName)“values(3,””+“VB.Net”+"")"
3.define the sqlcommend:
commend=new SqlCommend(sql,cnn);
4.associate the insert command:
adapter.InsertCommend=new SqlCommend(sql,cnn);
adapter.InsertCommend.ExecuteNonQuery();
5.close all objects:
commend.Dispose();
cnn.Close();

数据集数据表和数据网格视图
菜鸟笔记 ADO vs JDBC
When your datagridview contents get changed,you need to follow sentence to update the data in the database;
菜鸟笔记 ADO vs JDBC
JDBC

load driver

Ddrivermanagement is responsible for establishing the connection to the database through the driver
class.foName("")
connection conn=DriverManager.getConnection(url)

specify the URL to database server
The name and location of the database is given as a URL
the comms protocol+the machine holding the database+database port+the path to the database on the machine
statement objects
1.created
2.excuted
3.result collected