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
Never never use a database driver across an Internet connection, for any database, for any platform, for any client, anywhere. That goes double for mobile. Database drivers are designed for LAN operations and are not designed for flaky/intermittent connections or high latency.
And should go for:
DefaultHttpClient httpclient = new DefaultHttpClient();
But there is no example in how to open a connection or execute a simple sql statement. anyone could help me?
It uses the new credentials to create new database and table and insert values in it. Then it switches to Android Studio to show in simple steps of how to develop an App to interact with the MS SQL Server and database. It implements the required driver in the App's gradle file of the project.
Connect to a SQL Server instanceStart SQL Server Management Studio. The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine. For Server type, select Database Engine (usually the default option).
1- Make your own database (Sqlite) in your Android App. This means you have to synchronize via web services, with your server's database, whenever you see fit. Steps: a) Use an ORM to connect to your local database and to relational map your tables with your classes.
You should either use web services or implement an HTTP handler and transfer in a RESTful manner.
In order to connect to a MySQL server, you need a MySQL client. Android does not come with any MySQL libraries. You may be able to take a generic Java MySQL library and fudge it to work with Android, but that would be a big undertaking and wasted time.
The link you pointed to already told you that what you're trying to do is wrong in the first place. Don't connect to a database across the internet! You will need something on your server that responds to HTTP requests, looks up data in the database, and sends them back via HTTP. The link already mentioned a few options. You could even write something yourself, although it's most likely easier to use an existing solution than trying to make your own approach safe and hack-proof.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With