0

I am a new at Android apps. I want to connect the eclipse to SQL Server database. I created a database using Sql Server 2005 and use it in my website which implemented using asp.NET. Now I want to use the same database in my Android application because the the website and the application are linked together. I googled how to connect thee android with the sql database and I found that I should download (mysql-connector-java-5.1.18.jar) and include it into my project libraries using Build Path. I downloaded it but I don't know how to access to my sql database now?!

flx
  • 14,146
  • 11
  • 55
  • 70
user3287580
  • 93
  • 1
  • 9

2 Answers2

0

First of all, You will need to add a jar file to your project library as SQL Server 2000 Driver for JDBC Service. My target is SQL Server 2000, it will require the jar file called “sqljdbc4.jar”. This is not supported on Microsoft website now, you can download it here. For other versions of SQL Server, here is the link of SQL Server 2000 Driver for JDBC Service.

The following is the code for connection MS SQL Server and select some records from a testing table.

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

public class Main {
public static void main(String[] args) throws SQLException, ClassNotFoundException 
   {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
    Connection conn = DriverManager.getConnection("jdbc:sqlserver://HOSP_SQL1.company.com;user=name;password=abcdefg;database=Test");
    System.out.println("test");
    Statement sta = conn.createStatement();
    String Sql = "select * from testing_table";
    ResultSet rs = sta.executeQuery(Sql);
    while (rs.next()) {
        System.out.println(rs.getString("txt_title"));
    }
}
}
Dot_NET Pro
  • 2,095
  • 2
  • 21
  • 38
  • 1
    I am using SQL Server 2005 not 2000.. and I have already added the .jar file to my project library. And where should I write the code? – user3287580 Feb 18 '14 at 11:51
  • Write the code in you java file from which you want to connect to the database. Main function or any where – Dot_NET Pro Feb 18 '14 at 11:55
0

Use PHP script to connect SQL server.

Create PHP script and upload it into your FTP server. call the PHP file URL from your android application

Try below link.

connect to MS SQL Server database..

http://webcheatsheet.com/php/connect_mssql_database.php

http://webcheatsheet.com/php/connect_mysql_database.php

Run php script stored in the server..

Run php script stored in the server?

Community
  • 1
  • 1
suresh
  • 414
  • 3
  • 11
  • Suresh , he is asking about Sql Server 2005 not for mysql – Chintan Khetiya Feb 18 '14 at 11:40
  • @suresh Are you sure that will help me? I am using SQL Server 2005. Not using mysql. – user3287580 Feb 18 '14 at 11:54
  • sure. Use the first link to create PHP script. It will helpful for you – suresh Feb 18 '14 at 11:55
  • @suresh Thanks but I don't want to use PHPMyAdmin :( I want to use SQL server 2005 database. My website already use the SQL server 2005 database and now I want to use that database in my Android app. Sorry if annoying. I hope you undrstand me well and get what I am looking for. – user3287580 Feb 18 '14 at 12:09