JDBC通過SSH遠端連線Mysql資料庫

2021-09-05 10:17:35 字數 1281 閱讀 6930

@test

public void sshmysqltest() throws exception catch (exception e)

string driverclass =null;

string url = null;

string user = null;

string password = null;

//第一步:準備連線資料庫的4個引數:驅動名、jdbcurl,user,password

//1.讀取配置盤檔案

properties properties = new properties();

fileinputstream fileinputstream = new fileinputstream(new file("jdbc.properties"));

properties.load(fileinputstream);

fileinputstream.close();

//2.從配置檔案中獲取讀取的引數值

driverclass = properties.getproperty("driverclass");

url = properties.getproperty("url");

user = properties.getproperty("user");

password = properties.getproperty("password");

//第二步:載入驅動

class.forname(driverclass);

//第三步:通過drivermanager的getconnection方法獲取資料連線

以上**可分為兩層進行編輯,一層用於連線ssh並設定號本地**,另一層用於連線資料庫--(**已初步實現功能,**的部分優化後續再說)  o(∩_∩)o~嘿嘿

通過SSH連線遠端主機

要通過終端連線乙個遠端主機,正常的配置是直接在命令列中 ssh user 192.168.1.1 然後輸入秘密就好了.如果想通過ssh的方式進行免密碼登入,就要進行一定的配置.這裡的環境是mac linux之間的連線,首先通過命令列生成ssh密匙.一般在home目錄下的.ssh資料夾 隱藏 生成密匙...

通過JDBC遠端連線雲端資料庫

今天第一天學習jdbc,實現了使用jdbc遠端連線雲資料庫,實現方式可能會有些低階,特此記錄。使用手冊 解壓.zip後複製 bin.jar檔案到工程裡,然後右鍵 build path 加入工程,效果如圖 這一步首先要確認雲端資料庫使用者是否支援遠端連線,這裡可以參看教程 這是初始的方法,耦合性比較高...

遠端連線SSH

yum install openssh server 複製 service sshd start ps ef grep ssh 複製 chconfig sshd on 複製 ssh username ip 複製 kv host 別名hostname 主機名port 埠user 使用者名稱identi...