码迷,mamicode.com
首页 > 数据库 > 详细

JDBC NOTE

时间:2014-12-13 00:56:45      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

JDBC 基本流程:

1. 加载驱动

2.得到连接

3.创建PreparedStatement

4.执行操作

5.根据结果做处理

 

1. SQLSERVER

bubuko.com,布布扣
 1     String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
 2         String dbURL="jdbc:sqlserver://localhost:1433; DatabaseName=UserManager";
 3         String sqlUserName="sa";
 4         String userPwd="wfjts12332100";
 5         Connection dbConn=null;
 6         ResultSet rs=null;
 7         PreparedStatement ps=null;
 8         try
 9         {
10             Class.forName(driverName);
11             dbConn=DriverManager.getConnection(dbURL,sqlUserName,userPwd);
12             System.out.println("Connection Successful!");
13             ps=dbConn.prepareStatement("select * from users where id=? and passwd=? ");
14             ps.setObject(1, userName);
15             ps.setObject(2, password);
16             rs=ps.executeQuery();
17             if(rs.next())
18             {
19                 System.out.println("用戶合法");
20             }
21         }
22         catch(Exception ex)
23         {
24             ex.printStackTrace();
25         }
View Code

 

JDBC NOTE

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/aeolia/p/4160798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!