導航:首頁 > 編程大全 > 安卓與mysql資料庫

安卓與mysql資料庫

發布時間:2021-10-25 15:47:44

『壹』 mysql資料庫怎麼連接到安卓app

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=zzfeihua&password=12345&useUnicode=true&characterEncoding=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();
}
}
}
不過老是提示:
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably proced by a broken compiler.)

『貳』 安卓怎麼連mysql資料庫

https://..com/question/1577073124735088380.html
這里有類似的回復專
-供參考屬

『叄』 android連接mysql資料庫

這個,不建議你用Android程序去直連MySQL資料庫,不是做不到,而是我覺得這樣做不好,出於內安全容等方面考慮,(這篇博文:http://www.ways2u.com/?post=197有實現方法),你的資料庫地址,用戶名密碼,查詢SQL什麼的都存在程序里,很容易被反編譯等方法看到。
我建議你和你那做網頁前端的商量一下,讓他們把表示層和數據層邏輯分開,數據層對應網頁的表示層提供介面,同時在為你的Android手機端提供一個介面,簡介訪問資料庫,這介面可以2端都保持一致,比如XML+RPC或者json等等,Android端也有現成的東西能直接用,既安全又省事。

『肆』 android 如何連接mysql資料庫,並且往資料庫裡面插入數據

去看看httpget和httppost,再看一下servlet就可以實現一個簡單的連接了,連接寫在servlet裡面就好

『伍』 安卓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=zzfeihua&password=12345&useUnicode=true&characterEncoding=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 proced by a broken compiler.)

『陸』 有沒有安卓連接MySQL資料庫的軟體.方便管理的

一般MySQL都不由APP進行抄直接的遠程連接,而是交由後台伺服器進行封裝處理的。舉個例子。APP訪問--》後台PHP伺服器--》PHP訪問本地MySQL資料庫--》PHP返回查詢給APP所以,一般的APP分為兩部分,APP前端開發,PHP後台開發

『柒』 安卓怎麼連接mysql資料庫數據

現在不能直接連接,不過你可以再寫一個web伺服器端,通過java網路編程遠程訪問,web伺服器端返回xml數據再解析。這樣即使換了別的非android客戶端,也容易移植。

『捌』 Android 開發。。。如何連接到伺服器上的mysql資料庫

1、打開Tableau軟體。

『玖』 安卓系統怎麼裝mysql資料庫

這個,不建議你用Android程序去直連MySQL資料庫,不是做不到,而是我覺得這樣做不好,出於安全等方面考慮,你的資料庫地址,用戶名密碼,查詢SQL什麼的都存在程序里,很容易被反編譯等方法看到。
我建議你和你那做網頁前端的商量一下,讓他們把表示層和數據層邏輯分開,數據層對應網頁的表示層提供介面,同時在為你的Android手機端提供一個介面,簡介訪問資料庫,這介面可以2端都保持一致,比如XML+RPC或者json等等,Android端也有現成的東西能直接用,既安全又省事。

『拾』 android怎麼連接mysql資料庫

用Android程序去直連MySQL資料庫,覺得這樣做不好,出於安全等方面考慮。資料庫地址,用戶名密碼,查詢SQL什麼的都存在程序里,很容易被反編譯等方法看到。
建議把表示層和數據層邏輯分開,數據層對應網頁的表示層提供介面,同時在為Android手機端提供一個介面,簡介訪問資料庫,這介面可以2端都保持一致,比如XML+RPC或者json等等,Android端也有現成的東西能直接用,既安全又省事。

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=zzfeihua&password=12345&useUnicode=true&characterEncoding=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();

閱讀全文

與安卓與mysql資料庫相關的資料

熱點內容
如何加密u盤文件夾 瀏覽:860
網站懸浮窗代碼 瀏覽:4
蘋果5外屏都包括什麼 瀏覽:580
好看的愛情電影60分鍾左右的 瀏覽:453
P開頭 網站 瀏覽:98
學習計算機編程前景如何 瀏覽:930
寶馬gt大燈怎麼編程 瀏覽:755
北郵網路技術實踐 瀏覽:731
u盤不能讀取此卷無法識別的文件 瀏覽:300
讓管理會計信息化插上大數據翅膀 瀏覽:824
mysql每天取一條資料庫 瀏覽:606
schdoc是什麼文件 瀏覽:391
html源代碼下載 瀏覽:726
skype官方下載linux 瀏覽:496
新僵屍先生最後那個小孩去哪了 瀏覽:718
主角穿越三體開局創造暗位面 瀏覽:600
5s手機qq刪除最近文件在哪裡 瀏覽:404
在線免費網站看 瀏覽:471
右鍵添加程序 瀏覽:388
最新網址一;點此打開網站>>> 瀏覽:227

友情鏈接