⑴ 如何直接訪問網站的資料庫
1、先創建程序所要訪問的資料庫,打開控制梁渣面板,建立ODBC數據源:開始→設置→控制面板→管理工具→ODBC數據源→系統DSN。
2、然後編寫資料庫訪問程序:在程序中首先要載入驅動,其次要建立連接,再次創建嫌段用於訪問資料庫的芹渣譽Statement對象,然後利用Statement對象訪問資料庫
Class.forName(「sun.jdbc.odbc.JdbcOdbcDriver」);
Stringurl="jdbc:odbc:book";
Stringquery="SELECT*FROMbook1";
Connectionc=DriverManager.getConnection(Url,user,password);
Connectioncon=DriverManager.getConnection(url);
Statementstmt=con.createStatement();
ResultSetrs=stmt1.executeQuery(query);
建立連接之後,可以訪問資料庫,對資料庫進行操作,如:查詢、修改、刪除。
連接使用完畢,可以調用close()方法關閉連接.
importjava.sql.*;
classSimpleSelect{
publicstaticvoidmain(Stringargs[]){
Stringurl="jdbc:odbc:book";
Stringquery="SELECT*FROMbook1";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundExceptione){
System.err.print("ERROR:");
System.err.print(e.getMessage());
}
//輸出資料庫中信息
try{
Connectioncon=DriverManager.getConnection(url);
Statementstmt=con.createStatement();
ResultSetr=stmt.executeQuery(query);
System.out.println("id:"+""+"name"+""+"price"+""+"author"+""+"publish_name");
while(r.next()){
Longr1=r.getLong("id");
Stringr2=r.getString("name");
Doubler3=r.getDouble("price");
Stringr4=r.getString("author");
Stringr5=r.getString("publish_name");
System.out.println(r1+""+r2+""+r3+""+r4+""+r5);
}
r.close();
stmt.close();
con.close();
}catch(SQLExceptionex){
ex.printStackTrace();
}
}
⑵ 如何設置MSSQL資料庫訪問用戶及訪問許可權
您好,我來為您解答:
1.打開企業管理器.......進入sql server組..........安全性
2.創建、選擇洞銀你進行設置許可權的用戶,右擊屬性!
3.點擊標題欄下資料庫訪問,對其用戶設置給予訪問的數據和資料庫角色.
4.點擊確定,完成設置MSSQL資料庫訪問用戶及訪問許可權
轉載,僅供參考。碰激
納吵宴如果我的回答沒能幫助您,請繼續追問。
⑶ 軟體客戶端的電腦怎麼設置才能訪問區域網伺服器上的數據
不明確你說的是什麼軟體。一般情況上桐裂,可以找設置伺服器配置頁,服敗困務器局枯閉設置項輸入區域網伺服器的ip,埠號設置項輸入提供所需服務的埠
⑷ 如何設置MSSQL資料庫訪問用戶及訪問許可權
1.打開企業管理器.......進入sql
server組..........安全滲敏性2.創建、選擇你進行設置許可權的用戶,右叢孫擊屬性!3.點擊標題欄下資料庫訪問,對其用戶設置給予訪問滲喊鏈的數據和資料庫角色.4.點擊確定,完成設置mssql資料庫訪問用戶及訪問許可權
(責任編輯:winiis)