JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

SQLCMD SQL Server Command Line Tool

This section describes how to SQL Server command line tool - SQLCMD.

Before you start using Java programs to interact with SQL Server databases, you should learn some SQL Server client tools to run SQL statements on the SQL Server. SQLCMD, Query Analyzer, and Management Studio are good client tools to use. But SQLCMD comes with SQL Server 2005 Express Edition installation, and is ready to use.

This tutorial shows you how to use SQLCMD, a command line client tool, to run SQL statements on your local SQL Server databases.

When "sqlcmd" is started and connected to a SQL Server, it will you to enter statements or commands. You can enter one or more statements in one or more lines to form a Transact-SQL statement batch.

To end a batch of statements and send it to the SQL Server for execution, you need to enter the GO command. The following "sqlcmd" tutorial session sends two batches to the SQL Server:

C:\>sqlcmd -S localhost -U sa -P HerongYang
1> SELECT DB_NAME();
2> GO

------------------------
master

(1 rows affected)

1>QUIT
C:\

As you can see, I logged in to the server as "sa" with no problem. The "GO" command sends one SQL statement to the server. The returning output telling me that I was connected to the "master" database.

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 Downloading and Installing JDK - Java SE

 Installing and Running Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

 Java DB (Derby) - ResultSet Objects of Queries

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

 Oracle - Reference Implementation of JdbcRowSet

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

Microsoft SQL Server 2005 Express Edition

 Downloading Microsoft SQL Server 2005 Express Edition

 Installing Microsoft SQL Server 2005 Express Edition

SQLCMD SQL Server Command Line Tool

 Installing AdventureWorksLT Sample Database

 Microsoft JDBC Driver for SQL Server - sqljdbc.jar

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Summary of JDBC Drivers and Database Servers

 Additional Tutorial Notes to Be Added

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2007
SQLCMD SQL Server Command Line Tool