0

I'm new to connecting Java to SQL Server but hopefully I manage to connect them successfully through helps of various tutorials. But there are these methods and syntax that I couldn't explain for myself.

1.

                Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=login_DB;integratedSecurity=true");

Regarding the code above, what does integratedSecurity=true do?

2.

        String user = rss.getString(1);
        String pass = rss.getString(2);

Does the parameter inside getString(1) and getString(2) pertains to the column in the Database? And also, how does the ResultSet affects the getString()?

3.

while(rss.next()){
            String user = rss.getString(1);
            String pass = rss.getString(2);
               if(usernameTF.getText().trim().equals(user)&&passwordTF.getText().trim().equals( pass)){
                 count = 1;             
                }//if success   
            }//while    

Lastly, at least for now, does the while(rss.next()) method simply means that while there is a row in my table?

I know my code is a bad practice. But I am really trying my best to make it better.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Juju
  • 59
  • 1
  • 1
  • 8

3 Answers3

2
  1. Difference between Integrated Security = True and Integrated Security = SSPI

  2. Yes the number refers to the column number, or you can pass a String as the column name to pull data.

  3. Yes, whilst there is data in your ResultSet, for each iteration it will move the cursor to the next row of data available. Where you can access columns specifically using the syntax from part 2 of your question.

Hope this is useful.

Community
  • 1
  • 1
billy.mccarthy
  • 122
  • 1
  • 11
2
  1. Integrated Security = true/SSPI : the current Windows account credentials are used for authentication. Integrated Security = False : User ID and Password are specified in the connection String.
  2. rs.getString(1) - get 1 return column from your select statement. Select x,y,z from table; rs.getString(1) gives x column result for particular row.
  3. Your query returning n number row ,each time rs.next() check is there row available after current row.
Ragu
  • 373
  • 5
  • 15
1

According to Microsoft they are the same thing.

When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true.

There however is a difference between them according to the comment below:

True ignores User Id and Password if provided and uses those of the running process, SSPI it will use them if provided which is why MS prefers this. They are equivalent in that they use the same security mechanism to authenticate but that is it.

refer this link...!

Community
  • 1
  • 1
Rosh_LK
  • 680
  • 1
  • 15
  • 36