heyoo64
شنبه 05 اردیبهشت 1394, 09:53 صبح
سلام دوستان، میخوام به dbدر sqlserver که تحت شبکه است کانکت شم ولی نمیشه، این کد:
package com.shokouhi.masterconnecting;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import com.shokouhi.masterconnecting.R.string;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Connection conn=null;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://nayebsafety.ir:1433;DatabaseName=nayebsaf_na";
String user = "nayebsaf_fffff";
String password = "14741aS";
conn=DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
String query = "SELECT * from footer";
ResultSet result = stmt.executeQuery(query);
Toast.makeText(MainActivity.this, "Successful" , Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this, "No Connect" , Toast.LENGTH_LONG).show();
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("yes");
Toast.makeText(MainActivity.this, "yes" , Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this, "nono" , Toast.LENGTH_LONG).show();
System.out.println("nono");
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
فایل jar را هم اضافه کردم. لطفا راهنمایی کنید خیلی وقتم گرفته شده
package com.shokouhi.masterconnecting;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import com.shokouhi.masterconnecting.R.string;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Connection conn=null;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://nayebsafety.ir:1433;DatabaseName=nayebsaf_na";
String user = "nayebsaf_fffff";
String password = "14741aS";
conn=DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
String query = "SELECT * from footer";
ResultSet result = stmt.executeQuery(query);
Toast.makeText(MainActivity.this, "Successful" , Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this, "No Connect" , Toast.LENGTH_LONG).show();
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("yes");
Toast.makeText(MainActivity.this, "yes" , Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this, "nono" , Toast.LENGTH_LONG).show();
System.out.println("nono");
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
فایل jar را هم اضافه کردم. لطفا راهنمایی کنید خیلی وقتم گرفته شده