Results 1 to 7 of 7
- 01-06-2013, 12:32 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
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.
Thank you so muchJava 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) {} } } }Last edited by JosAH; 01-06-2013 at 12:40 PM. Reason: added [code] ... [/code] tags
- 01-08-2013, 10:57 AM #2
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
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.
- 01-08-2013, 11:15 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
- 01-08-2013, 11:50 AM #4
Re: Android java connecting to SQL server 2005
A web service isn't a web page.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-08-2013, 12:12 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
- 01-08-2013, 12:53 PM #6
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
- 01-08-2013, 01:41 PM #7
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
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
-
JDK 7 connecting to Remote MS SQL 2005 Server
By SnakeDoc in forum New To JavaReplies: 6Last Post: 08-30-2012, 05:02 PM -
problem connecting to ms sql server 2005
By naved in forum JDBCReplies: 0Last Post: 09-20-2011, 04:42 PM -
Connecting JTable With Microsoft SQL Server 2005 or Oracle
By WNIGAGLIONI in forum JDBCReplies: 0Last Post: 12-16-2008, 08:32 AM -
Having problem in connecting with SQL Server 2005
By rmaadil in forum JDBCReplies: 4Last Post: 05-21-2008, 06:55 AM -
Java connecting to sql server 2005
By pelegk2 in forum JDBCReplies: 0Last Post: 04-05-2008, 09:17 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks