`
wzdoxu
  • 浏览: 93807 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

使用JDBC方式操作数据库的步骤

阅读更多
使用JDBC方式操作数据库的步骤:

1、准备连接数据库的官方提供的JAR包

2、Import java.sql.*

//注册驱动

3、  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

//获得连接

4、  Connection con=DriverManager.getConnection(url,user,password);

//创建Statement

5、  Statement stmt=con.createStatement();

//执行SQL语句,获得返回结果

6、  ResultSet rt=stmt.executeQuery("select main from data");

//遍历结果集

7、  While(rt.next())

{

        System.out.Println(rt.getString(“data”))

}

//关闭结果集与连接

8、  rs.close();

9、  con.close();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics