Как Вы настраиваете DataSource в Java для соединения с SQL Server MS?

C #

public void TakeScreenshot()
{
    try
    {            
        Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
        ss.SaveAsFile(@"D:\Screenshots\SeleniumTestingScreenshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        throw;
    }
}
5
задан Eric Wilson 3 July 2009 в 18:06
поделиться

2 ответа

Start with the JDBC tutorial or the Microsoft docs.

and this:

String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driver);
String url = "jdbc:microsoft:sqlserver://host:1433/database";
Connection conn = DriverManager.getConnection(url, "username", "password");

Fill in your values for host, database, username, and password. The default port for SQL server is 1433.

UPDATE: Good point below. JDBC drivers can be had from both Microsoft and jTDS. I prefer the latter.

JNDI lookups have to do with Java EE app servers that support connection pooling. You can ask the app server to create a pool of connections, which can be an expensive thing to do, and loan them out to clients like library books as needed.

If you aren't using a Java EE app server or connection pooling, you have to create the connection on your own. That's where manual processes and DriverManager come in.

EXPLANATION: As for why the Sun tutorial shows DataSource twice, I'd say it's a case of poor editing. If you look above the code sample it says you can get a DataSource "by lookup or manually". The code snippet below shows both together, when it should be one or the other.

You know it's an inadvertent error because there's no way the code as written could compile. You have "ds" declared twice.

So it should read "...lookup", followed by its code snippet, and then "...manually", followed by its code snippet.

10
ответ дан 18 December 2019 в 06:23
поделиться

I like the jTDS driver for connecting to SQL Server.

A URL will look like this:

jdbc:jtds:sqlserver://localhost/Finance;instance=sqlexpress

Check this for jTDS Url Info.

This also has some interesting information to help troubleshoot jtds to sql express sorts of problems.

4
ответ дан 18 December 2019 в 06:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: