日期: 2020-06-23 17:41:28
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数据库代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对奥多码网站的支持!