Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i need to get data from sql server to my application in android mobile for that one

1. Installed sql server 2008 and created one database

2. Created sample project with jtds and sqljdbc4 jar files.

my code

Java
public class ConnectionTask extends AsyncTask<void,>
	{
		 Connection conn = null;
		  String connString = "jdbc:jtds:sqlserver://localhost:1433/Sample";
		@Override
		protected String doInBackground(Void... params) {
			
			 try {
	             String driver = "net.sourceforge.jtds.jdbc.Driver";
	             Class.forName(driver);
	          
	           
	            String username = "";
	            String password = "";
	            conn = DriverManager.getConnection(connString,username,password);
	            Log.d("Connection","open");       
	            Statement stmt = conn.createStatement();    
	            ResultSet reset = stmt.executeQuery("select * from sree");

	           //Print the data to the console    
	          while(reset.next()){
	            Log.d("Data:",reset.getString(1));
	          
	          }
	         conn.close();

	      } catch (Exception e)       
	         { 
	             Log.d("Error connection","" +
	           e.getMessage());
	          }
			return null;
		}
}

but it showing unable to connect to system and ConnREFuse like that

thanks in advance
Posted
Updated 21-Jan-14 6:59am
v4
Comments
Krunal Rohit 21-Jan-14 12:50pm    
Have you ever thought about WebServices ?
mekalareddy 21-Jan-14 12:57pm    
no sir , I need to access the database directly
Krunal Rohit 21-Jan-14 13:15pm    
I think you can't.. You can go to that destination via WebServices..
mekalareddy 23-Jan-14 6:55am    
k thanks for ur response

1 solution

 
Share this answer
 
Comments
mekalareddy 23-Jan-14 6:57am    
ya i tried this one but it showing not to conneted ur localhost address
Maciej Los 24-Jan-14 2:53am    
You can't connect to local host. You need to enable named pipe connection to MS SQL Seerver.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900