Java连接sqlserver2008数据库代码


    java连接sqlserver2008数据库代码如下所示:
    
public class SqlServer 
{ 
public static void main(String[] args) 
{ 
try 
{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=mydb;
", "user", "pass");
Statement st = conn.createStatement(); 
ResultSet rs=st.executeQuery("select * from aa10");
while (rs.next()) 
{ System.out.println(rs.getString(1)); 
} } catch (ClassNotFoundException e)
{ e.printStackTrace(); 
} catch (SQLException e)
{ e.printStackTrace(); 
} } }