package DataBasetesting;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnectMSSQLServer {
public static void main(String[] args) {
ConnectMSSQLServer connServer = new ConnectMSSQLServer();
//connServer.dbConnect("jdbc:sqlserver://localhost:1433;databaseName=Test;", "sa", "ram@123");
connServer.dbConnect("jdbc:sqlserver://localhost:1433;databaseName=test;", "sa", "Password");
}
public void dbConnect(String db_connect_string, String db_userid,String db_password)
{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(db_connect_string,
db_userid, db_password);
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = "select * from sysobjects where type='u'";
ResultSet rs = statement.executeQuery(queryString);
System.out.println("The Result Set is::"+rs.toString());
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnectMSSQLServer {
public static void main(String[] args) {
ConnectMSSQLServer connServer = new ConnectMSSQLServer();
//connServer.dbConnect("jdbc:sqlserver://localhost:1433;databaseName=Test;", "sa", "ram@123");
connServer.dbConnect("jdbc:sqlserver://localhost:1433;databaseName=test;", "sa", "Password");
}
public void dbConnect(String db_connect_string, String db_userid,String db_password)
{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(db_connect_string,
db_userid, db_password);
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = "select * from sysobjects where type='u'";
ResultSet rs = statement.executeQuery(queryString);
System.out.println("The Result Set is::"+rs.toString());
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment