0

I want to write a block of code that does accepts a username and then stores it into an MSSQL database. My approach to this is to create two objects (edittext and button), the edittext accepts a username, the button is simply a submit mechanic. I then create an onclicklistener, attach it to the submit button, and what it should then do is take the user entered text from the edittext, and store that into the mssql database.

I have a stored procedure that performs this task, I just need to write the supporting code around this function. I am unsure of where to put the required code (the syntax), do I open the connection, execute the SP and then close the connection all within the onclicklistener? What would that code look like? Please note that of course in the grand scheme of things I'm going to need to embellish the code to expand the acceptable parameters (such as checking to see if an identical username exists and such) but for the time being all I want to do exactly what I described.

User clicks "submit" after entering their new username, stored procedure executes and stores that username into a database.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Zerrubabel
  • 17
  • 3
  • 1
    You should do this asynchronously. Also you probably want to create a server-side API rather than executing SQL from Android directly, because SQL databases aren't really designed with the sort of security you'd need. – Ryan M Jul 29 '21 at 23:27
  • Regarding Ryan's latter point, see https://stackoverflow.com/q/15853367/115145. – CommonsWare Jul 29 '21 at 23:39
  • So you mean I should have a java file that specifically opens and closes the connection and runs the stored procedure, and then just reference the file on the front end? – Zerrubabel Jul 30 '21 at 05:41
  • 1
    Also @CommonsWare I've passed this onto the person on this project that I believe would benefit more from it (our work is divided a bit differently I feel than most people would do it). It is something to seriously consider though so I appreciate your link! – Zerrubabel Jul 30 '21 at 05:43

0 Answers0