0

嗨,我是 android 开发的新手,我目前正在开发一个需要连接到在线 mysql 数据库的 android 应用程序。我有在 netbeans 中进行 java 应用程序开发的经验,我在 netbeans 中使用以下代码通过 jdbc 驱动程序连接到 sql server....

 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;

 import net.sourceforge.jtds.jdbc.*;

 public void query2()
 {
 Log.i("Android"," MySQL Connect Example.");
  Connection conn = null;
 try {
 String driver = "net.sourceforge.jtds.jdbc.Driver";
 Class.forName(driver).newInstance();
 //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
 String connString = "jdbc:jtds:sqlserver://server_ip_address  :1433/DBNAME;encrypt=fasle;user=xxxxxxxxx;password=xxxxxxxx;instance=SQLEXPRESS;";
 String username = "xxxxxx";
 String password = "xxxxxxxxxx";
 conn = DriverManager.getConnection(connString,username,password);
  Log.w("Connection","open");
 Statement stmt = conn.createStatement();
 ResultSet reset = stmt.executeQuery("select * from TableName");

 //Print the data to the console
 while(reset.next()){
 Log.w("Data:",reset.getString(3));
  //              Log.w("Data",reset.getString(2));
 }
 conn.close();

   } catch (Exception e)
   {
   Log.w("Error connection","" + e.getMessage());
    }

但是在android中,我无处可寻,我对此一无所知,所以请任何人为相应的android应用程序编写我的代码,以便我可以理解差异...。任何帮助都将受到重视...

4

1 回答 1

0

您可以在 android 项目本身中使用 jtds(不是首选)

或者

使用 json,xml 通过 Http 解析(首选)

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

于 2014-12-29T11:31:17.197 回答