I created database in 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'". Even though the query is working fine when I execute it in 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). 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.