是否有可能我的Andr​​oid应用程序使用了PHP连接到MySQL数据库? [英] Is it possible to connect my android app to mysql database with out PHP.?

查看:196
本文介绍了是否有可能我的Andr​​oid应用程序使用了PHP连接到MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能我的Andr​​oid应用程序使用了PHP连接到MySQL数据库? 如果可能的话是什么,用于连接到MySQL分贝的替代方法。

解决方案

 是的,可以。
 

您必须添加一个罐子库mysql.Then的Java code将连接到MySQL服务器。

 进口java.lang.DriverManager中;

进口android.database.SQLException;

进口com.mysql.jdbc.Connection;
进口com.mysql.jdbc.ResultSet;
进口com.mysql.jdbc.Statement;


    公共类的SQLConnection {
        公共静态数Connection conn = NULL;
        静态无效setConnection(用户字符串,字符串通,字符串URL服务器,字符串的dBase){


              尝试
              {
                  字符串username =用户;
                  字符串password =通过;
                  字符串URL =的jdbc:mysql的://+ URL服务器+/+ dBase的;

                  的Class.forName(com.mysql.jdbc.Driver)的newInstance()。
                  康恩=的DriverManager.getConnection(URL,用户名,密码);
                  的System.out.println(数据库建立连接);
              }
              赶上(例外五)
              {
                  通信System.err.println(e.getMessage());
              }
              最后
              {
              }


        }
        公共静态连接的getConnection(){
        返回康涅狄格州;
        }

    }
 

Is it possible to connect my android app to mysql database with out PHP.? if it is possible what is the alternative way for connecting to mysql db.

解决方案

Yes, You can.

You have to add a jar library for mysql.Then java code that will connect to the mysql server.

import java.sql.DriverManager;

import android.database.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;


    public class SQLConnection {
        public static Connection conn = null;
        static void setConnection(String user,String pass,String urlServer,String dBase){   


              try
              {
                  String userName = user;
                  String password = pass;
                  String url = "jdbc:mysql://"+urlServer+"/"+dBase;

                  Class.forName ("com.mysql.jdbc.Driver").newInstance ();
                  conn = DriverManager.getConnection (url, userName, password);
                  System.out.println ("Database connection established");
              }
              catch (Exception e)
              {
                  System.err.println (e.getMessage());
              }
              finally
              {
              }


        }
        public static Connection getConnection(){
        return conn;
        }

    }

这篇关于是否有可能我的Andr​​oid应用程序使用了PHP连接到MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆