Hey everyone! I’m just starting out with Android development and I’m having trouble getting my app to talk to a Microsoft SQL Server 2008 database. I’m using the jtds-1.3.1.jar driver, but no luck so far.
Every time I try to connect, I get this error: Network error IOException: connection time out
I’m working in Eclipse Juno. Here’s a simplified version of what I’ve got:
public class DatabaseConnector extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
tryDatabaseConnection();
}
private void tryDatabaseConnection() {
TextView statusText = findViewById(R.id.status);
String dbUrl = "jdbc:jtds:sqlserver://192.168.1.100:1433;DatabaseName=MyShop";
String dbDriver = "net.sourceforge.jtds.jdbc.Driver";
String dbUser = "ShopUser";
String dbPass = "ShopPass123";
try {
Class.forName(dbDriver);
Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT TOP 1 * FROM Products");
if (rs.next()) {
statusText.setText("Connected: " + rs.getString(1));
}
} catch (Exception e) {
statusText.setText("Error: " + e.getMessage());
}
}
}
Any ideas what I’m doing wrong? Thanks in advance!