contacting mysql server database from android java - java

Hi i have my own hosting and i have created a database there in which i have two columns
host = "mysql.hostinger.in"
database = "mydatabase"
username = "myuser"
pass = "123"
TABLE = "Data"
'email' = column (TEXT)
'eligible' = column (INT)
now what i want to do is i need to contact my database to check if the email suppose "abc#xyz.com" is eligible ie. "1" means YES and "0" means NO
so how i connect to my database from android java any code snippet ?
also is this require to put password for database to contact ?
what if anybody decompile my application and get username and password then he can interfere which i do not want
do not want to put my sqldatabase password to fetch the data how could i do that ,someone said i need webservice to do that i am not good with php

If you have your own hosting, you could make little Rest, making and putting up PHP script on your server that returns for example JSON and get it in your App using JSON parser (f. ex. Volley Library). Your PHP file would hold all database connections etc

Related

How to get data from custom UID in firebase?

I have data structure like this for my android app. That can login and only see their profile. I dont make add content or do saving data to the database. So i created the data manually and the users only read and display the data.
How to make login,refer with username = "71140011" and password = "123456" which is inside real time database and the 71140011 only can see their profile only. thanks

How to display data from sql server with java [android studio]

I wish to display some data from my SQL server into my application.
Let me explain throw an example what have i done until now, and please tell me how should i go on with my work:
(1) I have a database named: 'DB1'
(2) In my database i have table named 'users':
Id, Name, LastName
1 Dave Stone
2 Rose Mary
3 Gray Lone
(3) I created 3 php files: 1/ config.php (sets up my database log in information like password...)
2/ DBConnection.php : `
// Connecting to database
public function connect() {
require_once 'Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
?>
3/ GetUsers.php which i dont know how should i write it - this would be the code which will echo whatever i want from the table.
(4) Inside my android studio project i have a MainActivity.java and i want to get all the LastNames of all the users in the database and do whatever with them... like print them into a text box it doesn't really matter (let's say i don't know how many users I have).
I need some one to help me get stages (3)3/ + (4) done / explained.
I think what you mean is a good method to retrieve and set values from app to database, the best and most prominent way is using basic REST services that convert your db values to JSON then you load the json using your api key as authentication, it might sound really stressful but is in fact very easy and flexible to implement, the only way you can directly set and get db values on android is using sqlite (android local inbuilt db)
The best tutorial and major explanation for exactly what you want to achieve is here
http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/
Then this one for further works
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
It covers how you make a rest service yourself

Can we set one database between Java and python?

I created python script that sends notifications when result declared but I want to make website that takes data of student email id and store in database.
Now here problem is that I don't know django framework so it takes time to make website.
Java, database connection, Data insertion,
Servelet calling easily do that by me.
Want to know way that java html css takes input from user and stores in database and then python program retrieves that data.
Hope you understand my question.
If you know python, I think Django might be a good choice for you. Django itself attempts to support as many features as possible on the backend. You only need to configure the database parameters in settings.py and Django ORM can automate the transfer of data stored in tables into objects. You don't have to implement the features yourself and it saves you tons of time.
Django has its own ModelForm class. It maps to the Models(eg. Student), it is quite easy to submit your Student info and store it in db.
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/path/to/my.cnf',
},
}
}
# my.cnf
[client]
database = NAME
user = USER
password = PASSWORD
default-character-set = utf8
If you insist using Java to implement the database backend, for sure you can share it with python. Some choices like JDBC, Hibernate and Mybatis.
Yes you can share the DB, you'll have to install the corresponding dependencies for connecting python to the DB as well as for Java. I've done this with postgresql, mysql and mssql

Android studio Login/Register ERROR

I've create an application LOGIN/REGISTER with this tutorial.
My problem is, if I put nothing on the register view of my app (name, username, age, password), it create an user on my table with nothing inside (just a number on "user_id" column) and I can sign in with nothing in "username" and "password" on the login view of my app.
And all my LOGIN/REGISTER android app becomes useless...
If you don't understand what I say, you can try my app.
For information, I've change some element to not give you all access to my app :
In "LoginRequest.class", I have change my website by xxx at this line :
private static final String LOGIN_REQUEST_URL ="http://xxxx.net/Login.php";
In "RegisterRequest.class", I have change my website by xxx at this line :
private static final String REGISTER_REQUEST_URL ="http://xxxx.net/Register.php";
In "Login.php", I have change my information at this line :
$con = mysqli_connect("mysql10.000host.com", "axxxxxxx_user", "passwordZ", "ayyyyyyy_data");
In "Register.php", I have change my information at this line :
$con = mysqli_connect("mysql10.000host.com", "axxxxxxx_user", "passwordZ", "ayyyyyyy_data");
Thank you for your help.
The only thing you need to do is validations
Put validation while registering and login. Don't call API if username, password and other fields are blank.
You need to check if user is entering a proper email-id , password should be more then 6 characters with combination of number and special character like stuff.
And in your server side do write procedures to validate the username or passwords.
You can also use an ORM which can protect you from injections.
Simple regex to vaid email-id would be
/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}#)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*#(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

fetching data from remote databases

I am trying to make application on google app engine which can fetch data from my other remote database , as far as i have learned that we can do it by using python in this way , If i am not wrong
import urllib
form_fields = {
"first_name": "Albert",
"last_name": "Johnson",
"email_address": "Albert.Johnson#example.com"
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded
Is is possible that i can fetch data from one of my this url using java and get the data store in datastore . Thanks
It is definitely possible to do it along those lines - is there a particular problem you're running into? Also, you may want to note that this means your remote database is exposed to the world, so you should have some means of protecting access to it.

Categories