Results 1 to 7 of 7
  1. #1
    natuyk is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Android java connecting to SQL server 2005

    Hello to all of you. Im new in this current trend using java and my project was run in eclipse hellios.
    I want to connect to sql server 2005. I just make a blank project in eclipse and copy the sample codes here in this forum. when i run it in emulator, the emulator pops up message that Sorry the application AnPOS ( process com.example.anupos) has stopped unexpectedly. Please try again..
    here is the code i copy and paste it in mainactivity.java. I already consider the tcpip enable using its port number..I also put in environment variable CLASSPATH and the value is the location of sqljdbc.jar.. I also include in external jar this sqljdbc.jar in the project.


    Java Code:
    package com.example.anupos;
    
    import java.sql.*;
    
    public class MainActivity  {
    
    
      
        public static void main(String[] args) {
            
            // Create a variable for the connection string.
            String connectionUrl = "jdbc:sqlserver://localhost:1057;" +
                "databaseName=PH9011;integratedSecurity=true;";
     
            // Declare the JDBC objects.
            Connection con = null;
            Statement stmt = null;
            ResultSet rs = null;
             
                try {
                    // Establish the connection.
                    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                        con = DriverManager.getConnection(connectionUrl);
                 
                        // Create and execute an SQL statement that returns some data.
                        String SQL = "SELECT * FROM CASHIER";
                        stmt = con.createStatement();
                        rs = stmt.executeQuery(SQL);
                 
                        // Iterate through the data in the result set and display it.
                        while (rs.next()) {
                            System.out.println(rs.getString(4) + " " + rs.getString(6));
                        }
                }
             
            // Handle any errors that may have occurred.
            catch (Exception e) {
                e.printStackTrace();
            }
     
            finally {
                if (rs != null) try { rs.close(); } catch(Exception e) {}
                    if (stmt != null) try { stmt.close(); } catch(Exception e) {}
                    if (con != null) try { con.close(); } catch(Exception e) {}
            }
        }
        
        
    }
    Thank you so much
    Last edited by JosAH; 01-06-2013 at 12:40 PM. Reason: added [code] ... [/code] tags

  2. #2
    viren2727in is offline Member
    Join Date
    Jan 2013
    Location
    INDIA
    Posts
    18
    Rep Power
    0

    Default Re: Android java connecting to SQL server 2005

    It is not advisable to create MSSQL connection from android, its better to create web service in server and use out put of web service in android.
    Last edited by viren2727in; 01-08-2013 at 06:39 PM.

  3. #3
    natuyk is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Re: Android java connecting to SQL server 2005

    Quote Originally Posted by viren2727in View Post
    Is not advisable to create MSSQL connection from android, its better to create web service in server and use out put of web service in android.
    but my manager dont want me to create a web page accessing sql server..He was an android apps like what he saw on registroid.com

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Android java connecting to SQL server 2005

    A web service isn't a web page.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    natuyk is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Re: Android java connecting to SQL server 2005

    Quote Originally Posted by DarrylBurke View Post
    A web service isn't a web page.

    db
    ah..ok i will research on this matter..thank you very much

  6. #6
    natuyk is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Re: Android java connecting to SQL server 2005

    Quote Originally Posted by DarrylBurke View Post
    A web service isn't a web page.

    db
    Sir can you give me some hint. i very new with this thing..im only know visual .net. Thank you

  7. #7
    viren2727in is offline Member
    Join Date
    Jan 2013
    Location
    INDIA
    Posts
    18
    Rep Power
    0

    Default Re: Android java connecting to SQL server 2005

    There is two types of web services available. 1. SOAP (Not Suitable for Mobile Application) 2. REST (also known as RESTfull)

    for mobile u have to use REST web services which returns data in text,JSON or XML format.
    Last edited by viren2727in; 01-08-2013 at 06:38 PM.

Similar Threads

  1. JDK 7 connecting to Remote MS SQL 2005 Server
    By SnakeDoc in forum New To Java
    Replies: 6
    Last Post: 08-30-2012, 05:02 PM
  2. Replies: 0
    Last Post: 09-20-2011, 04:42 PM
  3. Replies: 0
    Last Post: 12-16-2008, 08:32 AM
  4. Replies: 4
    Last Post: 05-21-2008, 06:55 AM
  5. Java connecting to sql server 2005
    By pelegk2 in forum JDBC
    Replies: 0
    Last Post: 04-05-2008, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •