㈠ 求C++操作SQL Server資料庫的源碼文件
一、配置:
1.設置SQLSERVER伺服器為SQL登錄方式,並且系統安全性中的sa用戶要設置登錄功能為「啟用」,還有必須要有友悔密碼。
2.需要在ODBC中進行數據源配置,數據源選」SQL SERVER」,登錄方式使用「使用輸入用戶登錄ID和密碼的SQL SERVER驗證」,並填寫登錄名(sa)和密碼,注意一點,密碼不能為空,這就意戚逗味著你的sa用戶必須得有密碼。否則無法通過系統本身的安全策略。測試通過就完成了配置。
二、連接初始化
1.在你所建立的C++項目中的stdafx.h頭文件中引入ADO
具體代碼如下
#import"c:.dll"
no_namespacerename("EOF","adoEOF")rename("BOF","adoBOF")
2.定義_ConnectionPtr變數後調用Connection對象的Open方法建立與伺服器的連接。
數據類型_ConnectionPtr實際上是由類模板_com_ptr_t得到的一個具體的實例類。_ConnectionPtr類封裝了Connection對象的Idispatch介面指針及其一些必要的操作。可以通過這個指針操縱Connection對象。
例如連接SQLServer資料庫,代碼如下:
//連接到MSSQLServer
//初始化指針
_ConnectionPtrpMyConnect=NULL;
HRESULThr=pMyConnect.CreateInstance(__uuidof(Connection));
if(FAILED(hr))
return;
//初始化鏈接參數
_bstr_tstrConnect="Provider=SQLOLEDB;
Server=127.0.0.1;
Database=mytest;
uid=sa;pwd=sa;";//Database指你系統中的資料庫
//執行連接
try
{
//Open方法連接字串必須四BSTR或者_bstr_t類型
pMyConnect->Open(strConnect,"","",NULL);
}
catch(_com_error&e)
{
MessageBox(e.Description(),"警告",MB_OK|MB_ICONINFORMATION);
}//發生鏈接錯誤
三、簡單的數據連接
//定義_RecordsetPtr變數,調用它Recordset對象的Open,即可打開一個數據集
//初始化過程以下是個實例
_RecordsetPtrpRecordset;
if(FAILED(pRecordset.CreateInstance(__uuidof(Recordset))))
{
return;
}
//執行操作
try
{
pRecordset->Open(_variant_t("userinfo"),
_variant_t((IDispatch*)pMyConnect),
adOpenKeyset,adLockOptimistic,adCmdTable);
}
catch(_com_error&e)
{
MessageBox("無法打開userinfo表","系統提示",
MB_OK|MB_ICONINFORMATION);
}
四、執行SQL語句
這里是關鍵,我認為只要你懂點SQL語句那麼一切都會方便許多比用上面的方法簡單,更有效率點。
首先
m_pConnection.CreateInstance(_uuidof(Connection));
//初始化Connection指針
m_pRecordset.CreateInstance(__uuidof(Recordset));
//初始化Recordset指針
CStringstrSql="select*fromtb_e_goods";//具體執行的SQL語句
m_pRecordset=m_pConnection->Execute(_bstr_t(strSql),
NULL,adCmdText);//將查詢數據導入m_pRecordset數據容器
至此 你的SQL語句已經執行完成了m_pRecordset內的數據就是你執行的結果。
取得記錄:
while(!m_pRecordset->adoEOF)//遍歷並讀取name列的記錄並輸出
{高告賣
CStringtemp=(TCHAR*)(_bstr_t)m_pRecordset->GetFields()->GetItem
("name")->Value;
AfxMessageBox(temp);
pRecordset->MoveNext();
}
五、插入記錄
//記得初始化指針再執行以下操作
CStringstrsql;
strsql.Format("insertintotb_e_goods(no,name,price)
values('%d','%s',%d)",m_intNo,m_strName,m_intPrice);
m_pRecordset=m_pConnection->
Execute(_bstr_t(strsql),NULL,adCmdText);
六、修改記錄
CStringstrsql;
strsql.Format("updatetb_e_goodssetname='%s',
price=%dwhereno=%d",m_strName,m_intPrice,m_intNo);
m_pRecordset=m_pConnection->Execute(_bstr_t(strsql),NULL,adCmdText);
七、刪除記錄
CStringstrsql;
strsql.Format("deletefromtb_e_goodswhereno='%d'",m_intNo);
m_pRecordset=m_pConnection->Execute(_bstr_t(strsql),NULL,adCmdText)A
其實要想使用C++玩轉SQLServer,最主要的還是要對SQL語句有所了解,才能方便的操作資料庫
㈡ 網站源碼資料庫怎麼是這樣
解決辦法是重新設置root用戶密碼,在Windows平台下操作步驟如下:
1、以系統管理員身份登錄到系統;
2、如果MySQL伺服器正在運行,停止它。
如果是作為Windows服務運行的伺服器,進入服務管理器:開始菜單->控制面板->管理工具->服務
如果伺服器不是作為服務而運行的,可能需要使用任務管理器來強制停止它。
3、創建1個文本文件,並將下述命令置於單一行中:
復制代碼代碼如下:
SET PASSWORD FOR'root'@'localhost'= PASSWORD('MyNewPassword');
用任意名稱保存該文件。在本例中,該文件為C:mysql-init.txt。
4、進入DOS命令提示:開始菜單->運行-> cmd
假定你已將MySQL安裝到C:mysql。如果你將MySQL安裝到了另一位置,請對下述命令進行相應的調整。
在DOS命令提示符下,執行命令:
復制代碼代碼如下:
C:> C:mysqlinmysqld-nt --init-file=C:mysql-init.txt
在伺服器啟動時,執行由「--init-file」選項(作用:在啟動時從指定的文件中讀取SQL命令)命名的文件的內容,更改根用戶密碼。當伺服器成功啟動後,應刪除C:mysql-init.txt。
5、停止MySQL伺服器,然後在正常模式下重啟它。如果以服務方式運行伺服器,應從Windows服務窗口啟動它。如果以手動方式啟動了伺服器,能夠像正常情形下一樣使用命令。
附其他方法:
方法一: 復制代碼代碼如下:
#/etc/init.d/mysqlstop
#mysqld_safe--user=mysql--skip-grant-tables--skip-networking&
#mysql-urootmysql
mysql>UPDATEuserSETPassword=PASSWORD('newpassword')whereUSER='root';
mysql>FLUSHPRIVILEGES;
mysql>quit
#/etc/init.d/mysqlrestart
#mysql-uroot-p
Enterpassword:<輸入新設的密碼newpassword>
mysql>
方法二:
直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:
復制代碼代碼如下:
#mysql-udebian-sys-maint-p
Enterpassword:<輸入[client]節的密碼>
mysql>UPDATEuserSETPassword=PASSWORD('newpassword')whereUSER='root';
mysql>FLUSHPRIVILEGES;
mysql>quit
#mysql-uroot-p
Enterpassword:<輸入新設的密碼newpassword>
mysql>
另一個方法
Windows:
1.管理員登陸系統,停止mysql服務或者結束mysqld-nt進程
2.進入命令行,來到mysql的安裝目錄.假設安裝目錄為d:mysql,CMD進入命令行
3.運行d:mysqlinmysqld-nt--skip-grant-tables啟動mysql,關閉許可權的檢查
4.運行d:mysqlinmysqladmin-urootflush-privilegespassword"newpassword"重設root密碼
5.重新啟動mysql服務
㈢ 求c#注冊登錄界面源代碼(全部包括SQL資料庫)
我寫了一個登錄的程序,界面也做的還可以,寫了號幾天呢。20分把這么多代碼寫給你不太可能吧,這里也放不下
㈣ 求一個SSH2登錄的源碼 oracle資料庫的 越詳細越好 本人新手!謝謝
我給你我原來寫過的吧。很久以前的了。只給你連接資料庫這些,其他的你自己看著寫吧。
下面是我當初寫的其中一個類,有注釋。你看看,大圓模仿著寫吧,肯定能寫旁陪出來。.
package com.;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
import com.tool.BaseTool;
public class BillDAO {
// 資料庫連接
private Connection con;
// 資料庫SQL語句執行者對象
private Statement stmt;
// 資料庫SQL語句執行運仿蠢者對象
private PreparedStatement pstmt;
// 資料庫SQL查詢結果集
private ResultSet rs;
// 打開資料庫連接
private void openConnection() {
try {
// 載入資料庫驅動
Class.forName("oracle.jdbc.driver.OracleDriver");
// 獲得資料庫連接
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcllib", "zxl", "zxl");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
// 關閉資料庫連接及資源
private void closeConnection() {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//檢查賬單編號是否存在的方法
@SuppressWarnings("finally")
public boolean checkBillNumber(long bill_number) {
boolean result = false;
openConnection();
// 編寫SQL語句
String sql = "select b.bill_number from bill b";
try {
// 實例化執行SQL語句的對象preparedstatement
stmt = con.createStatement();
// 執行查詢語句並返回結果集
rs = stmt.executeQuery(sql);
while (rs.next()) {
if (bill_number == rs.getLong("bill_number")) {
return result;
}
}
result = true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
return result;
}
}
//分頁顯示賬單列表的方法
@SuppressWarnings("finally")
public Result getPagingBill(int page_number, int page_data_number) {
Result result = null;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "select r.bill_number,r.goods_name,r.goods_number,r.transaction_amount," +
"r.value_name,r.supplier_name,r.goods_description,r.bill_date from " +
"(select rownum as rn,b.* from bill_list_view b) r where r.rn between "+
BaseTool.getPagingString(page_number, page_data_number);
try {
// 實例化執行SQL語句的對象preparedstatement
stmt = con.createStatement();
// 執行查詢語句並返回結果集
rs = stmt.executeQuery(sql);
// 將結果集儲存在Result對象當中
result = ResultSupport.toResult(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
return result;
}
}
//獲得賬單總數的方法
@SuppressWarnings("finally")
public int getBillCount() {
int result = 0;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "select count(b.bill_number) from bill_list_view b ";
try {
// 實例化執行SQL語句的對象preparedstatement
stmt = con.createStatement();
// 執行查詢語句並返回結果集
rs = stmt.executeQuery(sql);
// 取得賬單總數
while (rs.next()) {
result = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
return result;
}
}
//將用戶組合查詢的賬單列表分頁
@SuppressWarnings("finally")
public Result getFilterPagingBill(String goods_name, int pay_status ,
int page_number , int page_data_number){
Result result = null;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "select r.bill_number,r.goods_name,r.goods_number,r.transaction_amount," +
"r.value_name,r.supplier_name,r.goods_description,r.bill_date " +
" from (select rownum as rn,b.* from bill_list_view b where ";
String sql_last = ") r where r.rn between " + BaseTool.getPagingString(page_number, page_data_number);
// 將參數初始化
String value_name = "";
if (pay_status == 3)
value_name = "已付款";
else if (pay_status == 4)
value_name = "未付款";
else
value_name = null;
if ("".equals(goods_name.trim()))
goods_name = null;
// 按照用戶查詢的條件處理
try {
if (value_name != null && goods_name == null) {
sql = sql + "b.value_name=?" + sql_last;
pstmt = con.prepareStatement(sql);
pstmt.setString(1, value_name);
} else if (value_name == null && goods_name != null) {
goods_name = "%"+goods_name+"%";
sql = sql + "b.goods_name like ?" + sql_last;
pstmt = con.prepareStatement(sql);
pstmt.setString(1, goods_name);
} else {
goods_name = "%"+goods_name+"%";
sql = sql + "b.value_name=? and b.goods_name like ?" + sql_last;
pstmt = con.prepareStatement(sql);
pstmt.setString(1, value_name);
pstmt.setString(2, goods_name);
}
rs = pstmt.executeQuery();
result = ResultSupport.toResult(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeConnection();
return result;
}
}
//獲得用戶組合查詢的賬單總數
@SuppressWarnings("finally")
public int getFilterBillCount(String goods_name, int pay_status) {
int result = 0;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "select count(b.bill_number) from bill_list_view b where ";
// 將參數初始化
String value_name = "";
if (pay_status == 3)
value_name = "已付款";
else if (pay_status == 4)
value_name = "未付款";
else
value_name = null;
if ("".equals(goods_name.trim()))
goods_name = null;
// 按照用戶查詢的條件處理
try {
if (value_name != null && goods_name == null) {
sql = sql + "b.value_name=? ";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, value_name);
} else if (value_name == null && goods_name != null) {
goods_name="%"+goods_name+"%";
sql = sql + "b.goods_name like ? ";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, goods_name);
} else {
goods_name="%"+goods_name+"%";
sql = sql + "b.value_name=? and b.goods_name like ? ";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, value_name);
pstmt.setString(2, goods_name);
}
rs = pstmt.executeQuery();
while(rs.next()){
result = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeConnection();
return result;
}
}
//根據賬單編號獲得賬單詳細信息的方法
@SuppressWarnings("finally")
public Result getBillForBillNumber(long bill_number){
Result result = null;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "select b.* from bill_list_view b where b.bill_number="+bill_number;
try {
// 實例化執行SQL語句的對象preparedstatement
stmt = con.createStatement();
// 執行查詢語句並返回結果集
rs = stmt.executeQuery(sql);
// 將結果集儲存在Result對象當中
result = ResultSupport.toResult(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
return result;
}
}
//為賬單增加數據的方法
@SuppressWarnings("finally")
public int updateBill(List<Object> values){
//用於返回執行結果
int result = 0;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "insert into bill values (?,?,?,?,?,?,?,?)";
try {
// 實例化執行SQL語句的對象preparedstatement
pstmt = con.prepareStatement(sql);
//設置參數
for(int i=0,j=1;i<values.size();i++,j++){
if(values.get(i) instanceof Integer){
pstmt.setInt(j, (Integer)values.get(i));
}else if(values.get(i) instanceof Long){
pstmt.setLong(j, (Long)values.get(i));
} else if(values.get(i) instanceof String){
pstmt.setString(j, (String)values.get(i));
}else{
pstmt.setDate(j, (Date)values.get(i));
}
}
//獲得執行結果
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
//返回執行結果
return result;
}
}
//為賬單修改數據的方法
@SuppressWarnings("finally")
public int saveBill(List<Object> values){
//用於返回執行結果
int result = 0;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "update bill b set b.goods_name=?,b.goods_number=?,b.transaction_amount=?," +
"b.pay_status=?,b.supplier_number=?,b.goods_description=?,b.bill_date=? where b.bill_number=?";
try {
// 實例化執行SQL語句的對象preparedstatement
pstmt = con.prepareStatement(sql);
//設置參數
for(int i=0,j=1;i<values.size();i++,j++){
if(values.get(i) instanceof Integer){
pstmt.setInt(j, (Integer)values.get(i));
}else if(values.get(i) instanceof Long){
pstmt.setLong(j, (Long)values.get(i));
}else if(values.get(i) instanceof String){
pstmt.setString(j, (String)values.get(i));
}else{
pstmt.setDate(j, (Date)values.get(i));
}
}
//獲得執行結果
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
//返回執行結果
return result;
}
}
//刪除賬單中數據的方法
@SuppressWarnings("finally")
public int deleteBill(long bill_number){
//用於返回執行結果
int result = 0;
// 打開資料庫連接
openConnection();
// 編寫SQL語句
String sql = "delete bill b where b.bill_number=?";
try {
// 實例化執行SQL語句的對象preparedstatement
pstmt = con.prepareStatement(sql);
//設置參數
pstmt.setLong(1, bill_number);
//獲得執行結果
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 關閉資料庫連接及資源
closeConnection();
//返回執行結果
return result;
}
}
}
㈤ 易語言+php+資料庫做注冊登錄程序 怎麼做,最好是有教程跟源碼!
要是說教程,沒有哪個教程是指定講哪個問題的,這裡面涉及的知識,易語言操作mysql或post或網頁填表。教程都很好找。為什麼說或,因為常用大概就這三種方法。
直接操作資料庫,易語言直接鏈接網站的資料庫,可以不通過php來操作,直接把要注冊的帳號寫進資料庫,這是最直接的方法。
post,首先用httpwatch或其他抓包工具,抓取注冊時的數據包,然後用易語言(精益模塊)網頁_訪問這個方法來進行自製數據包提交。來完成注冊。
網頁填表,屬於在超文本瀏覽框內打開網站注冊頁面,然後模擬手動來填寫注冊信息。
建議使用的方法是post,因為直接操作資料庫安全性不高,網頁填表每次都要打開一次注冊頁面,效率不高,建議使用post方法。post視頻教程可以找 之乎者也的post教程,關於post的教程有很多
㈥ 易語言如何使用EDB資料庫實現注冊登錄源碼
直接添加空記錄,然笑含後寫內容關閉會提示碰做笑保存就行了,edb資料庫不太好用和方便建議用access資料庫吧。方便好胡困用