MY_BLOG

程序-----让生活更简单

BlogJava 首页 新随笔 联系 聚合 管理
  2 Posts :: 2 Stories :: 0 Comments :: 0 Trackbacks
总结的一些数据库最基本的操作 ,如有不对的地方,欢迎指出 

 

JAVA

C#

PHP

MYSQL

 
连接

driver="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/datebase";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);

执行

String sql = "insert into user(name) values(?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.executeUpdate();

返回结果集

ResultSet rs = ps.executeQuery();

string sqlstr = "select * from manavatar";
MySQLConnection DBConn 
= new MySQLConnection(new MySQLConnectionString("192.168.0.13""flashdata""root""root"3306).AsString);
DBConn.Open();
//MySQLDataAdapter myadap = new MySQLDataAdapter(sqlstr, conn);
MySQLCommand DBComm = new MySQLCommand(sqlstr,DBConn);
MySQLDataReader DBReader 
= DBComm.ExecuteReaderEx();
MySQLDataAdapter DTAdapter = new MySQLDataAdapter(sqlstr,DBConn);
DataSet myDataSet 
= new DataSet();
DTAdapter.Fill(myDataSet,
"manavatar");
 

连接 $conn=mysql_connect($db_server,$db_user_name,$db_user_password);
$flag=mysql_select_db($db_name,$conn);
执行 $result=mysql_query($sql);
返回结果集

 

MSSQL

driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
url = "jdbc:sqlserver://localhost:1433;databaseName=datebase";

连接

SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString = "Integrated Security=true;Initial Catalog=Northwind;Data Source=.\\SQLExpress";
dataConnection.Open();

执行

SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
dataCommand.CommandText = 
                    "SELECT OrderID, OrderDate, " +
                    "ShippedDate, ShipName, ShipAddress, ShipCity, " +
                    "ShipCountry "; 
dataCommand.CommandText += 
                    "FROM Orders WHERE CustomerID='" +
                    customerId + "'";

返回结果集 SqlDataReader dataReader = dataCommand.ExecuteReader();
 

$conn=@mssql_connect($db_server,$db_user_name,$db_user_password); 
@mssql_select_db($db_name,$conn);
$result=mysql_query($sql);

ORACLE

driver = "oracle.jdbc.driver.OracleDriver"; 
url = "jdbc:oracle:thin:@localhost:1521:datebase";

OracleConnection
OracleCommand
OracleDataReader

$conn=Ora_Logon("user@TNSNAME","password");
posted on 2011-02-11 20:42 Lihao 阅读(137) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问