简体   繁体   中英

Connecting android app to online mysql database

hi iam new to android development iam currently working on an android app that needs to connect to an online mysql database. I had experience in java application development in netbeans,I used the following code in netbeans to connect to an sql server by using jdbc driver....

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

but in android iam stuck at nowhere i don't know any thing about it,so can please any one write my code for a correspoding android application so that i can understand th difference ....any help would be apricited...

You can either use jtds in android project itself(not preferred)

or

use json,xml parsing by Http(preferred)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM