初學者的話,建議先確定自己的web用什麼語言設計,然後網路出Demo,很時候初學者去了解連接過程。然後在IIS發布出來配置資料庫數據源,最後再做一次測試,ok,希望我表達的言簡意賅
Ⅱ 我從網上下載了一個java web的項目,有一個.sql的資料庫文件。 如何連接項目和資料庫呢
1 導入可以在控制台用命令導入.這個難度比較大.也可以用工具導入 . navicat phpmyadmin都不錯.
2 網上下載的項目,應該已經寫好了資料庫連接的.你找一下dbPool之類的名字.具體看個人寫法.
3 能讀取插入數據,就是連接成功了.
Ⅲ C# web Web.config里sql連接資料庫
訪問資料庫有兩種方式:
Windows身份驗證登錄(不需要用戶名和密碼,適用於訪問本地資料庫,應用程序和SQL軟體安裝在同一台伺服器)
SQL Server 身份驗證登錄(適用於訪問其他計算機的資料庫,當然也可以用這種方式訪問本地資料庫)
根據樓主的情況應該用 SQL Server 身份驗證登錄
資料庫連接字元串一般寫在 connectionStrings節點下,非強制性(如寫在appsettings節點下),只不過這樣可以用
ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
方便訪問
以下是筆者的一個 web.config 文件的內容
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="connString" connectionString="Data Source=.;Initial Catalog=TestDatabase;Integrated Security=SSPI"/>
</connectionStrings>
</configuration>
附:資料庫連接字元串的寫法
SQL Server connection strings
SQL ODBC connection strings
Standard Security:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;"
Trusted connection:< br> "Driver={SQLServer};Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=yes;"
SQL OLE DB connection strings
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"
Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL OleDbConnection .NET strings
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;"
Trusted connection:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL SqlConnection .NET strings
Standard Security:
1. "Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;" < br>2. "Server=Your_Server_Name;Database=Your_Database_Name;UserID=Your_Username;Password=Your_Password;Trusted_Connection=False"
Trusted connection:
1. "Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
2."Server=Your_Server_Name;Database=Your_Database_Name;Trusted_Connection=True;"
希望回答對你有幫助
Ⅳ java web 怎麼連接sql資料庫
JAVA Web開發中與資料庫的連接操作,配置:
1、新建資料庫。
新建登錄角色,在新建資料庫的時候把資料庫的所有權交給你新建的角色。用用戶和密碼控制資料庫。保證資料庫的安全。
2、編寫context.xml文件 Xml文件的目的是封裝用戶和密碼,也是封裝的一種,方便操作。
以下為context.xml文件樣例:
<?xml version="1.0" encoding="utf-8"?>
<Context reloadable = "true">
<Resource
name="jdbc/sampleHS"
type="javax.sql.DataSource"
maxActive="14"
maxIdle="10"
username="hstaoshu"
maxWait="5000"
driverClassName="org.postgresql.Driver"
password="hstaoshu"
url="jdbc:postgresql://localhost:5432/hstaoshu"/>
</Context>
詳細說明:
name="jdbc/sampleHS"裡面的ssampHS是可改名稱,建議根據需要自己命名;
username="hstaoshu"
password="hstaoshu"此兩項為你新建的資料庫登錄角色用戶名和密碼信息,只有匹配 了才能訪問。這里簡單為了表示,把用戶名和密碼弄成了跟資料庫名字一樣。其實這是很不安全的。
url="jdbc:postgresql://localhost:5432/hstaoshu"/>
這是連接資料庫的URl,就像訪問網站的地址一樣。沒有這個是無法訪問資料庫的。localhost:5432表示本地埠。一般不需要改動,如果你在配置資料庫的時候改動過埠,那麼你需要把它改回來。/hstaoshu是你的資料庫名稱。
其他選項請勿擅自改動。
3、編寫DAO類。
DAO類的作用是與數據連接後,對資料庫的一些操作的封裝。封裝的作用。為了更好的數據管理。
DAO是真正如何使用資料庫的關鍵步驟,前兩步只是部署和配置。
private static InitialContext context = null;
private DataSource dataSource = null;
//一般把跟資料庫的連接放在DAO類的構造函數里,只要被實例化,就能和資料庫連接。
public BookDAO() {
try {
if (context == null) {
context = new InitialContext();
}
dataSource = (DataSource) context.lookup("java:comp/env/jdbc/sampleHS");
// 連接資料庫,前面在context.xml文件配置里的URl
} catch (NamingException e2) {
e2.printStackTrace();
}
}
public Connection getConnection() {
Connection conn = null;
try {
conn = dataSource.getConnection();// 獲得數據源的連接對象
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
做完上面的三步操作,開發環境已經完全和資料庫連接OK,可以開始資料庫的操作了。一般來說,對資料庫的操作語句都是提前封裝好的。這樣修改起來會對下面的代碼影響降到最小。
如下:
// ------------------資料庫操作語句代碼封裝------------------
/* 查看所有圖書 */
private static final String SELECT_ALL_SQL = "SELECT * FROM book";
那麼在使用的時候只要直接調用:
pstmt = conn.prepareStatement(SELECT_ALL_SQL);
Ⅳ 用Microsoft Visual Studio新建項目ASP.NET Web應用程序,怎麼連接到SQL資料庫,知道資料庫的IP地址
資料庫的地址就是資料庫安裝的電腦的IP地址,本機可以用127.0.0.1(前提是你配置對資料庫)
連接串一般就是
sqlconnection conn = new sqlconnection("server=127.0.0.1;user=sa;pwd=密碼;database=具體資料庫名");
conn.open();
Ⅵ ASP.NET中如何用WEB.CONFIG文件來連接SQL資料庫
cmd.Parameters.AddWithValue是對SQL語句進行添加參數,
Web.Config中的文件是保存的資料庫連接字元串。
使用方法string Sqlcon = System.Configuration.ConfigurationManager.AppSettings["connString"];
Ⅶ asp.net中如何配置web.config文件鏈接SQL資料庫
最好是用帶用戶和密碼的。
<add
name="connstr"
connectionstring="data
source=microsof-e46d5f\sql2005;initial
persist
security
info=true;uid=登陸帳戶;pwd=密碼;catalog=資料庫名;database=資料庫名、這倆個用哪個都可以,如果一起用系統會選擇database的"
providername="system.data.sqlclient"
/>
Ⅷ web登陸頁面,怎麼連接資料庫
建一個web.config頁面 裡面就是配資料庫連接的。。給你一段代碼 你看看:
<configuration>
<appSettings/>
<connectionStrings>
<!--鏈接SQL Server資料庫的鏈接字元串-->
<add name="Mispersonalconn" connectionString="data Source=(local);database=DB_Mispersonal;uid=sa;pwd=sa" providerName="System.Data.SqlClient"></add>
</connectionStrings>
<system.web>
<!--
設置 compilation debug="true" 將調試符號插入
已編譯的頁面中。但由於這會
影響性能,因此只在開發過程中將此值
設置為 true。
-->
<compilation debug="true"/>
<!--
通過 <authentication> 節可以配置 ASP.NET 使用的
安全身份驗證模式,
以標識傳入的用戶。
-->
<authentication mode="Windows"/>
<!--
如果在執行請求的過程中出現未處理的錯誤,
則通過 <customErrors> 節可以配置相應的處理步驟。具體說來,
開發人員通過該節可以配置
要顯示的 html 錯誤頁
以代替錯誤堆棧跟蹤。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<!--globalization fileEncoding="UTF-8" requestEncoding="UTF-8" responseEncoding="UTF-8" /-->
<globalization fileEncoding="gb2312" requestEncoding=" ...
Ⅸ 如何將一個基於Web的管理系統(類似學生管理系統)與一個SQL資料庫連接;
你後台用的是哪種語言?
Ⅹ 在WEB中如何連接到自己電腦里的SQL資料庫 有沒有知道 急需指教
可以的。參考如下:
SqlConnection conn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=資料庫名;Persist Security Info=True;User ID=sa;Password=1234;Connect Timeout=30;");
string sql = "select 123 as id";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();