filmov
tv
How to store image in MS SQL Server database and retrieve it from your Android App?

Показать описание
This video shows steps to create an Android App which connects to MS SQL Server Database.
It uses the MSSQL database to store the images in bytes array format. The respective data type in database server is VARBINARY(MAX).
It uses a couple of images stored in the emulator phone to demonstrate this App.
It reads those image files and then converts them to Bitmap and then to bytes array to store (insert) it in the database.
In the fetch method, once it receives the value of the VARBINARY data column from the database, it converts it back to the bytes array. Then it converts the bytes array back to bitmap. It uses an image view widget to display the bitmap image on the layout.
Complete source code and other details can be found in the below link:
However, the main Java code is copied below also for reference:
public class MainActivity extends AppCompatActivity {
private static String ip = "192.168.43.66";
private static String port = "1433";
private static String database = "testDatabase";
private static String username = "test";
private static String password = "test";
private static String url = "jdbc:jtds:sqlserver://"+ip+":"+port+"/"+database;
private Connection connection = null;
private TextView textView;
private EditText editTextIndex;
private EditText editTextFileName;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
try {
} catch (ClassNotFoundException e) {
} catch (SQLException e) {
}
}
public void buttonInsert(View view){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
}
catch (Exception e){
}
}
public void buttonFetch(View view){
try {
}
catch (Exception e){
}
}
}
-
It uses the MSSQL database to store the images in bytes array format. The respective data type in database server is VARBINARY(MAX).
It uses a couple of images stored in the emulator phone to demonstrate this App.
It reads those image files and then converts them to Bitmap and then to bytes array to store (insert) it in the database.
In the fetch method, once it receives the value of the VARBINARY data column from the database, it converts it back to the bytes array. Then it converts the bytes array back to bitmap. It uses an image view widget to display the bitmap image on the layout.
Complete source code and other details can be found in the below link:
However, the main Java code is copied below also for reference:
public class MainActivity extends AppCompatActivity {
private static String ip = "192.168.43.66";
private static String port = "1433";
private static String database = "testDatabase";
private static String username = "test";
private static String password = "test";
private static String url = "jdbc:jtds:sqlserver://"+ip+":"+port+"/"+database;
private Connection connection = null;
private TextView textView;
private EditText editTextIndex;
private EditText editTextFileName;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
try {
} catch (ClassNotFoundException e) {
} catch (SQLException e) {
}
}
public void buttonInsert(View view){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
}
catch (Exception e){
}
}
public void buttonFetch(View view){
try {
}
catch (Exception e){
}
}
}
-
Комментарии