//set path="C:\Program Files\Java\jdk1.7.0_25\bin"
// to compile use javac Conection,java and to run use java -classpath .;sqljdbc41.jar Conection
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conection
{
public static void main(String a[]) throws ClassNotFoundException, SQLException
{
try
{
// String url = "jdbc:sqlserver://localhost:1433//CSCLAP\\SQLEXPRESS;;;databaseName=employee";
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://CSCLAP\\SQLEXPRESS;databaseName=employee;integratedSecurity=true";// this is for windows authendication-SQLERVER 2012
// copy the file sqljdbc_auth.dll stored at D:\sqljdbc_6.2\enu\auth\x64 into "C:\Program Files\Java\jdk1.7.0_25\bin" */
// HElp Message
//If it provides the following error
//WARNING: Failed to load the sqljdbc_auth.dll cause : C:\Program Files\Java\jdk1.7.0_25\bin\sqljdbc_auth.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
//Exceptioncom.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:dc8585c2-c404-44fe-85a0-5d0fcdb2de97
// copy the file sqljdbc_auth.dll stored at D:\sqljdbc_6.2\enu\auth\x86 into "C:\Program Files\Java\jdk1.7.0_25\bin" */
//String url="jdbc:sqlserver://CSCLAP;instanceName=SQLEXPRESS;user=sa;password=sql;DatabaseName=employee";
// this is for sqlserver authendication
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
System.out.println("test");
Statement sta = conn.createStatement();
String Sql = "select * from emp";
ResultSet rs = sta.executeQuery(Sql);
while (rs.next()) {
System.out.println(rs.getString("eno"));
}
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}
// to compile use javac Conection,java and to run use java -classpath .;sqljdbc41.jar Conection
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conection
{
public static void main(String a[]) throws ClassNotFoundException, SQLException
{
try
{
// String url = "jdbc:sqlserver://localhost:1433//CSCLAP\\SQLEXPRESS;;;databaseName=employee";
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://CSCLAP\\SQLEXPRESS;databaseName=employee;integratedSecurity=true";// this is for windows authendication-SQLERVER 2012
// copy the file sqljdbc_auth.dll stored at D:\sqljdbc_6.2\enu\auth\x64 into "C:\Program Files\Java\jdk1.7.0_25\bin" */
// HElp Message
//If it provides the following error
//WARNING: Failed to load the sqljdbc_auth.dll cause : C:\Program Files\Java\jdk1.7.0_25\bin\sqljdbc_auth.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
//Exceptioncom.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:dc8585c2-c404-44fe-85a0-5d0fcdb2de97
// copy the file sqljdbc_auth.dll stored at D:\sqljdbc_6.2\enu\auth\x86 into "C:\Program Files\Java\jdk1.7.0_25\bin" */
//String url="jdbc:sqlserver://CSCLAP;instanceName=SQLEXPRESS;user=sa;password=sql;DatabaseName=employee";
// this is for sqlserver authendication
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
System.out.println("test");
Statement sta = conn.createStatement();
String Sql = "select * from emp";
ResultSet rs = sta.executeQuery(Sql);
while (rs.next()) {
System.out.println(rs.getString("eno"));
}
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}