java连接sqlserver2008数据库代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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(); } } } |
以上所述是小编给大家介绍的Java连接sqlserver2008数据库代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!