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(); } } }
以上所述是小编给大家介绍的Java连接sqlserver2008数据库代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/tech/database/236057.html