Java连接sqlserver2008数据库代码(javaee连接数据库登录到首页)这都可以?

随心笔谈11个月前发布 admin
87 0


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();
} } }

© 版权声明

相关文章