//sqljdbc42.jar in classpath
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String connectionURL = "jdbc:sqlserver://Server1\\Instance1;databaseName=DB1";
String login = "User1";
String password = "Password1";
String tableName = "AD_USER";
try {
//load driver here
Class.forName(driverName);
//use jdbc url, database login, and database password to create connection
java.sql.Connection conn = java.sql.DriverManager.getConnection(connectionURL, login, password);
java.sql.Statement stmt = conn.createStatement();
String dbQuery = null;
dbQuery = "TRUNCATE TABLE " + tableName; //delete all data from table
stmt.executeUpdate (dbQuery);
} catch (Exception e) { 
printErr(e.getLocalizedMessage()); 
}

Leave a Reply

Your email address will not be published. Required fields are marked *