How to add new Users into SQL server database through JAVA GUIHow can I restrict tables used in SQL Server database to Users from a Graphical User Interface?Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?How to make a new List in JavaHow do I escape a single quote in SQL Server?SQL Server: How to Join to first rowHow do I UPDATE from a SELECT in SQL Server?How to drop a table if it exists in SQL Server?How to Delete using INNER JOIN with SQL Server?How to set user Windows password in SQL Server

“T” in subscript in formulas

Tex Quotes(UVa 272)

What are some interesting features that are common cross-linguistically but don't exist in English?

Was there ever a treaty between 2 entities with significantly different translations to the detriment of one party?

Is for(( ... )) ... ; a valid shell syntax? In which shells?

Showing that the limit of non-eigenvector goes to infinity

Lost property on Portuguese trains

How do I make my image comply with the requirements of this photography competition?

How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?

Why are non-collision-resistant hash functions considered insecure for signing self-generated information

Why doesn't 'd /= d' throw a division by zero exception?

How to determine car loan length as a function of how long I plan to keep a car

Why do gliders have bungee cords in the control systems and what do they do? Are they on all control surfaces? What about ultralights?

Change my first, I'm entertaining

Sum ergo cogito?

What to say to a student who has failed?

Was it ever possible to target a zone?

Most natural way to use the negative with つもり

How to respectfully refuse to assist co-workers with IT issues?

What is the difference between "Grippe" and "Männergrippe"?

Network helper class with retry logic on failure

"Sorry to bother you" in an email?

Why in most German places is the church the tallest building?

Why do banks “park” their money at the European Central Bank?



How to add new Users into SQL server database through JAVA GUI


How can I restrict tables used in SQL Server database to Users from a Graphical User Interface?Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?How to make a new List in JavaHow do I escape a single quote in SQL Server?SQL Server: How to Join to first rowHow do I UPDATE from a SELECT in SQL Server?How to drop a table if it exists in SQL Server?How to Delete using INNER JOIN with SQL Server?How to set user Windows password in SQL Server






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am creating a GUI through Eclipse and am using Java; and the application connects to an SQL server database. I managed to add new users directly using Microsoft SQL server with their respective securables or restrictions.



However, I would like to add new users through the GUI itself and be able to determine which table they can access. Or at least just add new users and then ill figure out how to determine which table they can access. Im running into a problem converting the SQL code into Java, ( I am new to all this after all).



Thank you in advance,



Following is the SQL Code I found used in SQL Server to add new login and then a new User, the idea is to replace "NewAdminName" and "ABCD" with the actual user input directly from the GUI:



CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD'
GO

Use BEPAWI;
GO

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName')
BEGIN
CREATE USER [NewAdminName] FOR LOGIN [NewAdminName]
EXEC sp_addrolemember N'db_owner', N'NewAdminName'
END;


Following is the JAVA code Im am currently working on with Eclipse:



JButton btnNewButton = new JButton("Enter");
btnNewButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent arg0)

try

String username = "";
String password = "";
username = UsernametextField.getText().trim();
password = PasswordtextField.getText().trim();

if (username.equals("")

catch (SQLException se)

//handle errors for JDBC
se.printStackTrace();

catch (Exception a) //catch block

a.printStackTrace();



);


I believe my problem is this line of code:



resultSetInt = statement.executeUpdate("CREATE LOGIN '"+username+"' WITH PASSWORD = ''"+password+"'' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N''"+username+"'') BEGIN CREATE USER ['"+username+"'] FOR LOGIN ['"+username+"'] EXEC sp_addrolemember N'db_owner', N''"+username+"'' END;) VALUES('"+username+"', '"+password+"');");


Maybe I have to add all the columns from the SQL table? such as the
sys.database_principals and FROM sys.server_principals



Thank you again,










share|improve this question
























  • Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

    – cjungel
    Mar 27 at 18:35











  • Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

    – Paul Eames
    Mar 27 at 21:55


















0















I am creating a GUI through Eclipse and am using Java; and the application connects to an SQL server database. I managed to add new users directly using Microsoft SQL server with their respective securables or restrictions.



However, I would like to add new users through the GUI itself and be able to determine which table they can access. Or at least just add new users and then ill figure out how to determine which table they can access. Im running into a problem converting the SQL code into Java, ( I am new to all this after all).



Thank you in advance,



Following is the SQL Code I found used in SQL Server to add new login and then a new User, the idea is to replace "NewAdminName" and "ABCD" with the actual user input directly from the GUI:



CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD'
GO

Use BEPAWI;
GO

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName')
BEGIN
CREATE USER [NewAdminName] FOR LOGIN [NewAdminName]
EXEC sp_addrolemember N'db_owner', N'NewAdminName'
END;


Following is the JAVA code Im am currently working on with Eclipse:



JButton btnNewButton = new JButton("Enter");
btnNewButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent arg0)

try

String username = "";
String password = "";
username = UsernametextField.getText().trim();
password = PasswordtextField.getText().trim();

if (username.equals("")

catch (SQLException se)

//handle errors for JDBC
se.printStackTrace();

catch (Exception a) //catch block

a.printStackTrace();



);


I believe my problem is this line of code:



resultSetInt = statement.executeUpdate("CREATE LOGIN '"+username+"' WITH PASSWORD = ''"+password+"'' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N''"+username+"'') BEGIN CREATE USER ['"+username+"'] FOR LOGIN ['"+username+"'] EXEC sp_addrolemember N'db_owner', N''"+username+"'' END;) VALUES('"+username+"', '"+password+"');");


Maybe I have to add all the columns from the SQL table? such as the
sys.database_principals and FROM sys.server_principals



Thank you again,










share|improve this question
























  • Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

    – cjungel
    Mar 27 at 18:35











  • Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

    – Paul Eames
    Mar 27 at 21:55














0












0








0








I am creating a GUI through Eclipse and am using Java; and the application connects to an SQL server database. I managed to add new users directly using Microsoft SQL server with their respective securables or restrictions.



However, I would like to add new users through the GUI itself and be able to determine which table they can access. Or at least just add new users and then ill figure out how to determine which table they can access. Im running into a problem converting the SQL code into Java, ( I am new to all this after all).



Thank you in advance,



Following is the SQL Code I found used in SQL Server to add new login and then a new User, the idea is to replace "NewAdminName" and "ABCD" with the actual user input directly from the GUI:



CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD'
GO

Use BEPAWI;
GO

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName')
BEGIN
CREATE USER [NewAdminName] FOR LOGIN [NewAdminName]
EXEC sp_addrolemember N'db_owner', N'NewAdminName'
END;


Following is the JAVA code Im am currently working on with Eclipse:



JButton btnNewButton = new JButton("Enter");
btnNewButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent arg0)

try

String username = "";
String password = "";
username = UsernametextField.getText().trim();
password = PasswordtextField.getText().trim();

if (username.equals("")

catch (SQLException se)

//handle errors for JDBC
se.printStackTrace();

catch (Exception a) //catch block

a.printStackTrace();



);


I believe my problem is this line of code:



resultSetInt = statement.executeUpdate("CREATE LOGIN '"+username+"' WITH PASSWORD = ''"+password+"'' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N''"+username+"'') BEGIN CREATE USER ['"+username+"'] FOR LOGIN ['"+username+"'] EXEC sp_addrolemember N'db_owner', N''"+username+"'' END;) VALUES('"+username+"', '"+password+"');");


Maybe I have to add all the columns from the SQL table? such as the
sys.database_principals and FROM sys.server_principals



Thank you again,










share|improve this question














I am creating a GUI through Eclipse and am using Java; and the application connects to an SQL server database. I managed to add new users directly using Microsoft SQL server with their respective securables or restrictions.



However, I would like to add new users through the GUI itself and be able to determine which table they can access. Or at least just add new users and then ill figure out how to determine which table they can access. Im running into a problem converting the SQL code into Java, ( I am new to all this after all).



Thank you in advance,



Following is the SQL Code I found used in SQL Server to add new login and then a new User, the idea is to replace "NewAdminName" and "ABCD" with the actual user input directly from the GUI:



CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD'
GO

Use BEPAWI;
GO

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName')
BEGIN
CREATE USER [NewAdminName] FOR LOGIN [NewAdminName]
EXEC sp_addrolemember N'db_owner', N'NewAdminName'
END;


Following is the JAVA code Im am currently working on with Eclipse:



JButton btnNewButton = new JButton("Enter");
btnNewButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent arg0)

try

String username = "";
String password = "";
username = UsernametextField.getText().trim();
password = PasswordtextField.getText().trim();

if (username.equals("")

catch (SQLException se)

//handle errors for JDBC
se.printStackTrace();

catch (Exception a) //catch block

a.printStackTrace();



);


I believe my problem is this line of code:



resultSetInt = statement.executeUpdate("CREATE LOGIN '"+username+"' WITH PASSWORD = ''"+password+"'' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N''"+username+"'') BEGIN CREATE USER ['"+username+"'] FOR LOGIN ['"+username+"'] EXEC sp_addrolemember N'db_owner', N''"+username+"'' END;) VALUES('"+username+"', '"+password+"');");


Maybe I have to add all the columns from the SQL table? such as the
sys.database_principals and FROM sys.server_principals



Thank you again,







java sql user-interface






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 18:18









Paul EamesPaul Eames

12 bronze badges




12 bronze badges















  • Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

    – cjungel
    Mar 27 at 18:35











  • Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

    – Paul Eames
    Mar 27 at 21:55


















  • Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

    – cjungel
    Mar 27 at 18:35











  • Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

    – Paul Eames
    Mar 27 at 21:55

















Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

– cjungel
Mar 27 at 18:35





Instead of creating actual database users you could consider having a single user for the application and then modeling application users in tables where you store users, credentials, roles, permissions, etc. Also, you can consider avoiding making blocking calls from the GUI thread as it will block the interface. Separating GUI from business logic and data access is also a good idea.

– cjungel
Mar 27 at 18:35













Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

– Paul Eames
Mar 27 at 21:55






Thank you for your reply Cjungel. I thought we separated all three logical models, we have the database with SQL server, the GUI where the user interacts and then the actual code itself, however we are new to this; and this is for school. If I understand correctly you are saying to just use one user to login into the server and then create a whole new table called users, depending on that table each user will have permission to the other tables? Also, there is no way of going forward with the way we are doing it?

– Paul Eames
Mar 27 at 21:55













1 Answer
1






active

oldest

votes


















0















Ok, so I figured it out. WOHOOO!!!



Im adding the code in case someone else needs it.



Now to figure out how to restrict certain tables to each new user....



Thank you,



try password.equals(""))

JOptionPane.showMessageDialog(null," name or password is wrong","Error",JOptionPane.ERROR_MESSAGE);

else

connection = DriverManager.getConnection(AdminMenu.DATABASE_URL, AdminMenu.UserName, AdminMenu.Password);
statement = connection.createStatement();


resultSetInt = statement.executeUpdate("CREATE LOGIN "+username+" WITH PASSWORD = '"+password+"'");
resultSetInt = statement.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'"+username+"') CREATE USER ["+username+"] FOR LOGIN ["+username+"] EXEC sp_addrolemember N'db_owner', N'"+username+"'");

//("CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') BEGIN CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] EXEC sp_addrolemember N'db_owner', N'NewAdminName' END;) VALUES('"+username+"', '"+password+"');");

String SMessage = "Record added for "+username;

// create dialog ox which is print message
JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
//close connection
((java.sql.Connection)connection).close();




catch (SQLException se)

//handle errors for JDBC
se.printStackTrace();

catch (Exception a) //catch block

a.printStackTrace();


}
});





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384067%2fhow-to-add-new-users-into-sql-server-database-through-java-gui%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    Ok, so I figured it out. WOHOOO!!!



    Im adding the code in case someone else needs it.



    Now to figure out how to restrict certain tables to each new user....



    Thank you,



    try password.equals(""))

    JOptionPane.showMessageDialog(null," name or password is wrong","Error",JOptionPane.ERROR_MESSAGE);

    else

    connection = DriverManager.getConnection(AdminMenu.DATABASE_URL, AdminMenu.UserName, AdminMenu.Password);
    statement = connection.createStatement();


    resultSetInt = statement.executeUpdate("CREATE LOGIN "+username+" WITH PASSWORD = '"+password+"'");
    resultSetInt = statement.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'"+username+"') CREATE USER ["+username+"] FOR LOGIN ["+username+"] EXEC sp_addrolemember N'db_owner', N'"+username+"'");

    //("CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') BEGIN CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] EXEC sp_addrolemember N'db_owner', N'NewAdminName' END;) VALUES('"+username+"', '"+password+"');");

    String SMessage = "Record added for "+username;

    // create dialog ox which is print message
    JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
    //close connection
    ((java.sql.Connection)connection).close();




    catch (SQLException se)

    //handle errors for JDBC
    se.printStackTrace();

    catch (Exception a) //catch block

    a.printStackTrace();


    }
    });





    share|improve this answer





























      0















      Ok, so I figured it out. WOHOOO!!!



      Im adding the code in case someone else needs it.



      Now to figure out how to restrict certain tables to each new user....



      Thank you,



      try password.equals(""))

      JOptionPane.showMessageDialog(null," name or password is wrong","Error",JOptionPane.ERROR_MESSAGE);

      else

      connection = DriverManager.getConnection(AdminMenu.DATABASE_URL, AdminMenu.UserName, AdminMenu.Password);
      statement = connection.createStatement();


      resultSetInt = statement.executeUpdate("CREATE LOGIN "+username+" WITH PASSWORD = '"+password+"'");
      resultSetInt = statement.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'"+username+"') CREATE USER ["+username+"] FOR LOGIN ["+username+"] EXEC sp_addrolemember N'db_owner', N'"+username+"'");

      //("CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') BEGIN CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] EXEC sp_addrolemember N'db_owner', N'NewAdminName' END;) VALUES('"+username+"', '"+password+"');");

      String SMessage = "Record added for "+username;

      // create dialog ox which is print message
      JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
      //close connection
      ((java.sql.Connection)connection).close();




      catch (SQLException se)

      //handle errors for JDBC
      se.printStackTrace();

      catch (Exception a) //catch block

      a.printStackTrace();


      }
      });





      share|improve this answer



























        0














        0










        0









        Ok, so I figured it out. WOHOOO!!!



        Im adding the code in case someone else needs it.



        Now to figure out how to restrict certain tables to each new user....



        Thank you,



        try password.equals(""))

        JOptionPane.showMessageDialog(null," name or password is wrong","Error",JOptionPane.ERROR_MESSAGE);

        else

        connection = DriverManager.getConnection(AdminMenu.DATABASE_URL, AdminMenu.UserName, AdminMenu.Password);
        statement = connection.createStatement();


        resultSetInt = statement.executeUpdate("CREATE LOGIN "+username+" WITH PASSWORD = '"+password+"'");
        resultSetInt = statement.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'"+username+"') CREATE USER ["+username+"] FOR LOGIN ["+username+"] EXEC sp_addrolemember N'db_owner', N'"+username+"'");

        //("CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') BEGIN CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] EXEC sp_addrolemember N'db_owner', N'NewAdminName' END;) VALUES('"+username+"', '"+password+"');");

        String SMessage = "Record added for "+username;

        // create dialog ox which is print message
        JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
        //close connection
        ((java.sql.Connection)connection).close();




        catch (SQLException se)

        //handle errors for JDBC
        se.printStackTrace();

        catch (Exception a) //catch block

        a.printStackTrace();


        }
        });





        share|improve this answer













        Ok, so I figured it out. WOHOOO!!!



        Im adding the code in case someone else needs it.



        Now to figure out how to restrict certain tables to each new user....



        Thank you,



        try password.equals(""))

        JOptionPane.showMessageDialog(null," name or password is wrong","Error",JOptionPane.ERROR_MESSAGE);

        else

        connection = DriverManager.getConnection(AdminMenu.DATABASE_URL, AdminMenu.UserName, AdminMenu.Password);
        statement = connection.createStatement();


        resultSetInt = statement.executeUpdate("CREATE LOGIN "+username+" WITH PASSWORD = '"+password+"'");
        resultSetInt = statement.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'"+username+"') CREATE USER ["+username+"] FOR LOGIN ["+username+"] EXEC sp_addrolemember N'db_owner', N'"+username+"'");

        //("CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' GO USE BEPAWI GO IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') BEGIN CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] EXEC sp_addrolemember N'db_owner', N'NewAdminName' END;) VALUES('"+username+"', '"+password+"');");

        String SMessage = "Record added for "+username;

        // create dialog ox which is print message
        JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
        //close connection
        ((java.sql.Connection)connection).close();




        catch (SQLException se)

        //handle errors for JDBC
        se.printStackTrace();

        catch (Exception a) //catch block

        a.printStackTrace();


        }
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 23:10









        Paul EamesPaul Eames

        12 bronze badges




        12 bronze badges



















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384067%2fhow-to-add-new-users-into-sql-server-database-through-java-gui%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript