Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
SqlServerJdbcConnection.java - sqljdbc JDBC Connection Example
How to create a JDBC connection to SQL Server database using the sqljdbc JDBC driver? I want to see a Java program example.
✍: FYIcenter.com
If you have a SQL Server running on your local computer
with TCP/IP protocol turned on and listening on port 1433,
you can use the following example, SqlServerJdbcConnection.java,
to learn how to create a JDBC connection:
// Copyright (c) 2016 FYIcenter.com
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
// Example of sqljdbc JDBC connection to SQL Server
public class SqlServerJdbcConnection {
public static void main(String [] args) throws Exception {
// Build the sqljdbc JDBC connection URL
String url = "jdbc:sqlserver://localhost;user=sa;password=fyicenter";
Connection con = DriverManager.getConnection(url);
System.out.println("JDBC connection and database server information:");
DatabaseMetaData meta = con.getMetaData();
System.out.println("Database Product Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Product Version: "
+ meta.getDatabaseProductVersion());
System.out.println("Driver Name: "
+ meta.getDriverName());
System.out.println("Driver Version: "
+ meta.getDriverVersion());
System.out.println("JDBC Major Version: "
+ meta.getJDBCMajorVersion());
System.out.println("JDBC Minor Version: "
+ meta.getJDBCMinorVersion());
// Close the connection
con.close();
}
}
You can compile and run the above example in a command window as shown below:
C:\fyicenter>\local\jdk-1.8.0\bin\javac SqlServerJdbcConnection.java C:\fyicenter>\local\jdk-1.8.0\bin\java -cp .;C:\local\sqljdbc_6.0\enu\sqljdbc42.jar SqlServerJdbcConnection JDBC connection and database server information: Database Product Name: Microsoft SQL Server Database Product Version: 12.00.2000 Driver Name: Microsoft JDBC Driver 6.0 for SQL Server Driver Version: 6.0.7728.100 JDBC Major Version: 4 JDBC Minor Version: 2
The output confirms that:
⇒ SqlServerJdbcUrl.java - sqljdbc JDBC Connection URL Example
⇐ SQL Server SQLEXPRESS Service for sqljdbc Test
2016-12-24, ∼3050🔥, 0💬
Popular Posts:
JDK 17 jdk.jdi.jmod is the JMOD file for JDK 17 JDI (Java Debug Interface) tool. JDK 17 JDI tool com...
What Is ojdbc5.jar for Oracle 11g R1? ojdbc5.jar for Oracle 11g R1 is the JAR files of ojdbc.jar, JD...
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
JDK 11 jdk.jlink.jmod is the JMOD file for JDK 11 JLink tool, which can be invoked by the "jlink" co...
How to download and install JDK (Java Development Kit) 1.3? If you want to write Java applications, ...