Example: [java] package Utils; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. SQLException; import java. SQL. statement; public class DB {private static Connection con = null; private static Statement statement = null; private static ResultSet set = null; private String SQL = ""; // load the JDBC driver private static String driverNameOfSqlServer = "c Om. microsoft. sqlserver. jdbc. SQLServerDriver "; // ip address (changed to your own IP address) private static String DatabaseIP =" localhost "; // database username private static String DatabaseUser =" sjf "; // Database Password private static String DatabasePassword = "123456"; // database name private static String DatabaseName = "pubs"; // URL private static String DatabaseUrl = "jdbc: sqlserver: // "+ database IP +": 1433; DatabaseName = "+ DatabaseName ;/ /Obtain the Connection public Connection getConnection () {try {// register the driver Class. forName (driverNameOfSqlServer); // obtain the connection con = DriverManager. getConnection (DatabaseUrl, DatabaseUser, DatabasePassword);} catch (Exception e) {System. out. println ("getConnection error"); e. printStackTrace ();} return con;} // creates a session public Statement getStatement (Connection con) {if (con! = Null) {try {statement = con. createStatement (); return statement;} catch (SQLException e) {System. out. println ("getStatement error"); e. printStackTrace () ;}} return null ;}// query public ResultSet getResultSetQuery (Statement statement, String SQL) {if (statement! = Null) {try {set = statement.exe cuteQuery (SQL); return set;} catch (SQLException e) {System. out. println ("getResultSetQuery error"); e. printStackTrace () ;}} return null;} // Add, modify, and delete the public void getResultSetUpdate (Statement statement, String SQL) {if (statement! = Null) {try {statement.exe cuteUpdate (SQL);} catch (SQLException e) {System. out. println ("getResultSetUpdate error"); e. printStackTrace () ;}}// close the Connection to public static void colse (Connection con) {if (con! = Null) {try {con. close ();} catch (SQLException e) {e. printStackTrace () ;}}// close the public static void close (Statement statement) {if (statement! = Null) {try {statement. close ();} catch (SQLException e) {e. printStackTrace () ;}}// close the query set public static void close (ResultSet set) {if (set! = Null) {try {set. close ();} catch (SQLException e) {e. printStackTrace () ;}}} package Utils; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. SQLException; import java. SQL. statement; public class DB {private static Connection con = null; private static Statement statement = null; private static ResultSet set = null; private String SQL = ""; // Load SqlServer JDBC driver private static String driverNameOfSqlServer = "com. microsoft. sqlserver. jdbc. SQLServerDriver "; // ip address (changed to your own IP address) private static String DatabaseIP =" localhost "; // database username private static String DatabaseUser =" sjf "; // Database Password private static String DatabasePassword = "123456"; // database name private static String DatabaseName = "pubs"; // URLprivate static String DatabaseUrl = "jdbc: sqlserver: // "+ DatabaseIP + ": 1433; DatabaseName =" + DatabaseName; // obtain the Connection public Connection getConnection () {try {// register the driver Class. forName (driverNameOfSqlServer); // obtain the connection con = DriverManager. getConnection (DatabaseUrl, DatabaseUser, DatabasePassword);} catch (Exception e) {System. out. println ("getConnection error"); e. printStackTrace ();} return con;} // creates a session public Statement getStatement (Connection con) {if (con! = Null) {try {statement = con. createStatement (); return statement;} catch (SQLException e) {System. out. println ("getStatement error"); e. printStackTrace () ;}} return null ;}// query public ResultSet getResultSetQuery (Statement statement, String SQL) {if (statement! = Null) {try {set = statement.exe cuteQuery (SQL); return set;} catch (SQLException e) {System. out. println ("getResultSetQuery error"); e. printStackTrace () ;}} return null;} // Add, modify, and delete the public void getResultSetUpdate (Statement statement, String SQL) {if (statement! = Null) {try again statement.exe cuteUpdate (SQL);} catch (SQLException e) {System. out. println ("getResultSetUpdate error"); e. printStackTrace () ;}}// close the Connection to public static void colse (Connection con) {if (con! = Null) {try {con. close ();} catch (SQLException e) {e. printStackTrace () ;}}// close the public static void close (Statement statement) {if (statement! = Null) {try {statement. close ();} catch (SQLException e) {e. printStackTrace () ;}}// close the query set public static void close (ResultSet set) {if (set! = Null) {try {set. close ();} catch (SQLException e) {e. printStackTrace () ;}}} test: [java] DB db = new DB (); Connection con = db. getConnection (); Statement statement = db. getStatement (con); String SQL = "select * from dbo.jobs"; ResultSet rs = db. getResultSetQuery (statement, SQL); try {if (rs. next () {System. out. println ("fdfsdfsdff" + rs. getString ("job_desc");} catch (SQLException e) {e. printStackTrace ();} www.2cto.com DB = new db (); Connection con = DB. getConnection (); Statement statement = db. getStatement (con); String SQL = "select * from dbo.jobs"; ResultSet rs = db. getResultSetQuery (statement, SQL); try {if (rs. next () {System. out. println ("fdfsdfsdff" + rs. getString ("job_desc");} catch (SQLException e) {e. printStackTrace ();}