package com.example.jaroslavh.myapplication1;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
GetUser();
} catch (Exception e) {
print(e.toString());
}
}
public void GetUser() throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Properties props = new Properties();
props.setProperty("user", "SYSDBA");
props.setProperty("password", "masterkey");
props.setProperty("encoding", "UTF8");
Connection connection = DriverManager.getConnection(
"jdbc:firebirdsql:192.168.0.96/3050:C:/IBExpert/db/TEST1.FDB",
props);
Statement statement = null;
String query = " SELECT * FROM users";
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayList<User> users = new ArrayList<User>();
while (resultSet.next()) {
users.add(new User(resultSet.getInt("ID"), resultSet.getString("NAME"), resultSet.getInt("PASSWD")));
}
ArrayAdapter<User> adapter = new ArrayAdapter<User>(this, android.R.layout.simple_spinner_item, users);
spinner.setAdapter(adapter);
// ArrayAdapter<User> adapter = new ArrayAdapter<User>(this, android.R.layout.simple_spinner_item, new User[]{// new User(1, "Петя", 111),// new User(2, "Саша", 222),// new User(3, "Вася", 333),// });
}
public void Exit(View view) {
finishAffinity();
}
public void In(View view) {
Intent intent = new Intent(this, ListOperations.class);
intent.putExtra("p1", "hello");
startActivity(intent);
}
void print(String message) {
Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG);
toast.show();
}
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
GetUser();
} catch (Exception e) {
print(e.toString());
}
}
public void GetUser() throws Exception {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Properties props = new Properties();
props.setProperty("user", "SYSDBA");
props.setProperty("password", "masterkey");
props.setProperty("encoding", "UTF8");
Connection connection = DriverManager.getConnection(
"jdbc:firebirdsql:192.168.0.96/3050:C:/IBExpert/db/TEST1.FDB",
props);
Statement statement = null;
String query = " SELECT * FROM users";
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayList<User> users = new ArrayList<User>();
while (resultSet.next()) {
users.add(new User(resultSet.getInt("ID"), resultSet.getString("NAME"), resultSet.getInt("PASSWD")));
}
ArrayAdapter<User> adapter = new ArrayAdapter<User>(this, android.R.layout.simple_spinner_item, users);
spinner.setAdapter(adapter);
// ArrayAdapter<User> adapter = new ArrayAdapter<User>(this, android.R.layout.simple_spinner_item, new User[]{// new User(1, "Петя", 111),// new User(2, "Саша", 222),// new User(3, "Вася", 333),// });
}
public void Exit(View view) {
finishAffinity();
}
public void In(View view) {
Intent intent = new Intent(this, ListOperations.class);
intent.putExtra("p1", "hello");
startActivity(intent);
}
void print(String message) {
Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG);
toast.show();
}
}
package com.example.jaroslavh.myapplication1; /** * Created by jaroslav.h on 30.05.2017. */ public class User { int id; String name; int pass; User(int id, String name, int pass) { this.id = id; this.name = name; this.pass = pass; } User(){ } @Override public String toString() { return name; } }
Комментариев нет:
Отправить комментарий