[英]Why queries won't work even though connection with database is ok?
I created database in SQL Server Management Studio.我在 SQL Server Management Studio 中创建了数据库。 My connection with database is ok, but query I try to execute is causing problems.我与数据库的连接正常,但我尝试执行的查询导致问题。 It throws me "Invalid object name 'tw__towar'".它向我抛出“无效的 object 名称 'tw__towar'”。 Even though the query is working fine when I execute it in SQL Server Management Studio.即使当我在 SQL Server Management Studio 中执行查询时查询工作正常。
Here is code fragment responsible for connection.这是负责连接的代码片段。
try {
Class.forName(ssmsDriver);
connection = DriverManager.getConnection(url, userName, userPassword);
Log.d(TAG, "onCreate: connected to the database");
} catch (ClassNotFoundException e) {
e.printStackTrace();
Log.e(TAG, "onCreate: class not found", e);
} catch (SQLException e) {
e.printStackTrace();
Log.e(TAG, "onCreate: sql exception", e);
}
And here is code responsible for executing query.这是负责执行查询的代码。 Double underscore intended.双下划线的意思。
try {
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT tw_nazwa FROM tw__towar" +
" WHERE tw_ean='5903206038608';");
mItemNameTextView.setText("SUCCESS"); // DELETE THIS LATER
} catch (SQLException e) {
e.printStackTrace();
mItemNameTextView.setText(e.getMessage()); // DELETE THIS LATER
}
Does anybody have any idea what may be causing problem?有人知道可能导致问题的原因吗?
I managed to solve this problem, so I'll post answer here for anyone that would have the same issue in the future.我设法解决了这个问题,所以我会在这里为将来遇到同样问题的任何人发布答案。
The problem was that I tried to operate on the sa account (system administrator).问题是我试图对sa帐户(系统管理员)进行操作。 I could connect to database but it cut off my access to tables.我可以连接到数据库,但它切断了我对表的访问。
To solve this problem you need to create new login by:要解决此问题,您需要通过以下方式创建新登录:
I hope it will help someone in the future.我希望它会在未来对某人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.