Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import android.annotation.SuppressLint;
- import android.widget.TextView;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import org.w3c.dom.Text;
- import java.sql.*;
- public class MainActivity extends AppCompatActivity {
- @SuppressLint("SetTextI18n")
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- String dbName = "Web";
- String serverip="178.217.172.237";
- // String serverport="2433";
- String url = "jdbc:sqlserver://"+serverip+"\\isubase"+";databaseName="+dbName+"";
- Statement stmt = null;
- ResultSet result = null;
- String databaseUserName = "secret";
- String databasePassword = "secret";
- Connection conn = null;
- String rs = null;
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- // Подключение к базе данных
- conn = DriverManager.getConnection(url, databaseUserName, databasePassword);
- // Отправка запроса на выборку и получение результатов
- stmt = conn.createStatement();
- result = stmt.executeQuery("SELECT Параметры,цена2 FROM Товар");
- // Обход результатов выборки
- while (result.next()) {
- rs+=result.getString("Параметры");
- }
- TextView textView = (TextView)findViewById(R.id.textview);
- textView.setText(rs);
- // Закрываем соединение
- result.close();
- stmt.close();
- conn.close();
- } catch (SQLException | ClassNotFoundException ex) {
- ex.printStackTrace();
- TextView textview = (TextView)findViewById(R.id.textview);
- textview.setText(ex.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement