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();