本文目錄一覽:
- 1、app怎麼訪問mysql資料庫
- 2、Android 開發。。。如何連接到伺服器上的mysql資料庫
- 3、安卓app 怎麼連接mysql
- 4、Android手機app 鏈接伺服器的mysql 讀取資料庫
- 5、iOS 開發中,可以實現app直接連接伺服器上的mysql資料庫直接取數據么?
app怎麼訪問mysql資料庫
app怎麼訪問mysql資料庫
android 鏈接mysql資料庫實例:
package com.hl;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
Android 開發。。。如何連接到伺服器上的mysql資料庫
1、打開Tableau軟體。
2、在連接中,找到紅框位置的MySQL,點擊開始連接Mysql。
3、在彈出的連接界面,輸入Mysql伺服器地址、埠、用戶名、密碼。
4、輸入完成後,點擊紅框位置 確認 進行連接。
5、此時已經連接到MySQL伺服器上,為了測試 我們點擊紅框位置 選擇資料庫查看一下。
安卓app 怎麼連接mysql
android 鏈接mysql資料庫實例:
package com.hl;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class AndroidMsql extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sqlCon();
}
});
}
private void mSetText(String str){
TextView txt=(TextView)findViewById(R.id.txt);
txt.setText(str);
}
private void sqlCon(){
try {
Class.forName(“com.mysql.jdbc.Driver”);
} catch (Exception e) {
e.printStackTrace();
}
try {
String url =”jdbc:mysql://192.168.142.128:3306/mysql?user=zzfeihuapassword=12345useUnicode=truecharacterEncoding=UTF-8″;//鏈接資料庫語句
Connection conn= (Connection) DriverManager.getConnection(url); //鏈接資料庫
Statement stmt=(Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql=”select * from user”;//查詢user表語句
ResultSet rs=stmt.executeQuery(sql);//執行查詢
StringBuilder str=new StringBuilder();
while(rs.next()){
str.append(rs.getString(1)+”\n”);
}
mSetText(str.toString());
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
不過eclipse老是提示:
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn’t come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
Android手機app 鏈接伺服器的mysql 讀取資料庫
手機是不能直接去連接你伺服器的mysql資料庫
請在你的服務端寫代碼去連接mysql數據吧
Mysql連接方法
1. 載入資料庫驅動: Class.forName(“org.gjt.mm.mysql.Driver”); //載入資料庫驅動
String url = “jdbc:mysql://localhost:3306/test”;
String user = “root”;
String passowrd = “123456”;
2. 獲取資料庫連接Connection con數= DriverManager.getConnection(url,user,password)
3. 獲取SQL執行器 PreparedStatement prepare = con.prepareStatement(“SQL語句”)
4. 執行SQL語句,得到結果集 ResultSet result = prepare.executeQuery();
while(result.next()){
//讀取結果
}
最後不要忘記導入jdbc驅動包
純工手打字,請採納哈
iOS 開發中,可以實現app直接連接伺服器上的mysql資料庫直接取數據么?
理論上是可以直接讀取資料庫的,相當於遠程連接著數據。簡單說明一下,就是用客戶端組件,設置資料庫地址、埠、用戶、密碼,然後直接select
update,把命令提交到資料庫。
但問題在於資料庫的信息,用戶密碼存儲在客戶端,容易給反編譯出來(難度這個我不清楚,你做ios開發可能清楚點)。而當發生安全問題的時候,要改密碼或者資料庫地址,麻煩事就來了,總不能讓用戶再升級一次(ios的發布期你也知道)。
此外還要考慮數據在傳輸過程中是否加密,是否證書方式,現在的網路,劫持植入廣告滿街都是。好像蘋果那邊有限制今後的新軟體要ssl才行。
原創文章,作者:TCRNS,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/315757.html