How to connect Android to a database server

前端 未结 6 1819
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 04:12

Is there any sample? I have my android application and I need to connect to mysql server on my machine, what is the best way?

I should not use jdbc, explanation here

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 04:36

    I tried to connect DatabaseServer from an Android Application,initially i faced some issue while i was using jtds, jar package for database Driver Support, instead of using jtds jar file use mysql-Connector jar file for Database Driver Support. mysql-connector jar file "mysql-connector-java-5.1.24-bin.jar". put this jar file in projects libs folder.

    a little bit code snippet :

    `String url="jdbc:mysql://(IP-of databaseServer):3306/DBNAME";`
    `String driver="org.gjt.mm.mysql.Driver";`
    `String username="XYZ";//user must have read-write permission to Database
    `String password= "*********";`//user password
    
    `try{
        Class.forName(driver).newInstance();//loading driver
        Connection con = DriverManager.getConnection(url,username,password);
        /*once we get connection we can execute ths SQL command to Remote Database Server with the help mysql-connector driver over Internet*/
    
    }`    
    `catch(Exception e){
        e.printStackTrace();
    }`
    

    I hope it could work.

    Cheers Rajesh P Yadav.

提交回复
热议问题