我是连接 Java 到 SQL Server 的新手,但希望我能够通过各种教程的帮助成功连接它们。但有些方法和语法我自己无法解释。
1.
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=login_DB;integratedSecurity=true");
对于上面的代码,integratedSecurity=true
做了什么?
2.
String user = rss.getString(1);
String pass = rss.getString(2);
getString(1)
和 getString(2)
中的参数是否与数据库中的列相关?另外,ResultSet
如何影响 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
最后,至少现在,while(rss.next())
方法是否仅仅意味着 while 我的表中有一行?
我知道我的代码是一种不好的做法。但我真的正在尽力让它变得更好。
最佳答案
- Integrated Security = true/SSPI:当前 Windows 帐户凭据用于身份验证。 Integrated Security = False:用户 ID 和密码在连接字符串中指定。
- rs.getString(1) - 从 select 语句中获取 1 个返回列。 从表中选择x、y、z; rs.getString(1) 给出特定行的 x 列结果。
- 您的查询返回 n 行,每次 rs.next() 检查当前行之后是否有可用行。
关于java - 这个方法有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30499646/