"com.microsoft.jdbc.sqlserver.SQLServerDriver";

邢臻
2023-12-01
import java.sql.Connection;
import java.sql.DriverManager;


public class TestCenter {

	public static void main(String[] args) 
	{
		String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
		String dbURL = "jdbc:microsoft:sqlserver://192.168.1.109:5090; DatabaseName=anorder";
		String userName = "sa";
		String userPwd = "123";

		try {
			Class.forName(driverName);
			Connection conn = DriverManager.getConnection(dbURL, userName, userPwd);
			System.out.println("Connection Successful!");
			java.sql.Statement stmt = conn.createStatement();
			java.sql.ResultSet rs = stmt.executeQuery("select getdate() as date ");
			//if (rs.next()) System.err.println("@@@ >> "+rs.getString(1));
			java.sql.ResultSetMetaData rmd = rs.getMetaData();
			int cnt = rmd.getColumnCount()+1;
			while (rs.next())
			{
				for (int i=1; i<cnt; i++) System.err.print("\t  "+rmd.getColumnName(i)+"["+i+"]="+rs.getString(i));
				System.err.println( );
			}
			rs.close();
			stmt.close();
			conn.close();
			conn = null;
			System.out.println("Connection down ~ !");
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
}

 类似资料:

相关阅读

相关文章

相关问答