Java连接sqlserver2008数据库代码
程序员文章站
2022-03-27 21:41:19
java连接sqlserver2008数据库代码如下所示:public class sqlserver { public static void main(string[] args) { try {...
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数据库代码,希望对大家有所帮助
推荐阅读