【发布时间】:2011-11-30 18:26:41
【问题描述】:
我在连接到本地 SQL Server 2008 R2 时遇到问题,
代码如下:
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:jtds:sqlserver://192.168.2.101:1433/INSERTGT";
String dbName = "podmiot";
String driver = "net.sourceforge.jtds.jdbc.Driver";
String userName = "user";
String password = "pass";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
int duration = Toast.LENGTH_SHORT;
Toast.makeText(getApplicationContext(), "Connected to the database", duration);
conn.close();
System.out.println("Disconnected from database");
EditText edit1 = (EditText)findViewById(R.id.editText1);
edit1.setText("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
TextView edit1 = (TextView)findViewById(R.id.exception);
edit1.setText("Problem: " + e.toString());
}
错误:
当我尝试建立连接时出现错误:java.sql.SQLException: Network error IOException: localhost/127.0.0.1:1433 - connection refused.
对不起我的英语... :) 谢谢帮助
【问题讨论】:
-
是否有防火墙可以阻止该端口上的流量?
-
您可能不希望您的用户名/密码出现在问题中
标签: java sql connection