求大神教我怎样用selenium和Java链接数据库呗。之前有人提过是要下载SSMS,但我下完不会用,求帮助。~~~~(>_<)~~~~
我还试了用sqljdbc4.jar 但是不知道我运行代码后出错了。求解救。。。
代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.openqa.selenium.WebDriver;
public class connectsql {
public static void main(String[] args) {
String connectionUrl="jdbc:sqlserver://localhost:1433;databaseName=myCC;intefratedSecurity=true;";
WebDriver driver = null; Connection con = null; Statement stmt = null; ResultSet rs=null; try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
System.out.println("Connection Established");
String SQL ="Select * from [myCC 0106] where [EnterpriseID]='a.f.bado'";
stmt =con.createStatement();
rs=stmt.executeQuery(SQL);
while(rs.next()){
System.out.println("PeopleKey shold be 2"+rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:ad35d678-f62d-4bc8-9300-b816877a4a51
|