zoukankan      html  css  js  c++  java
  • jdbc for mssql2005 demo

    package com.huawei.sqlserver;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public class SqlTest {
    	public static void main(String[] args) throws SQLException {
    
    		Connection conn = null;
    		PreparedStatement stmt = null;
    		ResultSet rs = null;
    
    		try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    			conn = DriverManager.getConnection(
    					"jdbc:sqlserver://localhost:1433;databaseName=test", "sa", "123");
    			stmt = conn.prepareStatement("select * from T_User where id=?");
    			stmt.setInt(1, 10);
    			rs = stmt.executeQuery();
    			while (rs.next()) {
    				System.out.println(rs.getInt("id"));
    				System.out.println(rs.getString("name"));
    				System.out.println(rs.getDate("birthday"));
    				System.out.println("----------------------------");
    			}
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} finally {
    			if (rs != null)
    				rs.close();
    			if (stmt != null)
    				stmt.close();
    			if (conn != null)
    				conn.close();
    		}
    	}
    
    }
    

      

  • 相关阅读:
    mybatis(十)缓存
    mybatis(八)复杂查询
    mybatis(六)分页
    mybatis(九)动态SQL
    mybatis(七)只用注解开发
    mybatis(五) 日志
    log4j.properties 相关配置
    mybatis(四)中可能出现的问题
    MyBatis(三) 配置解析
    IIS 发布 .net core 3.1
  • 原文地址:https://www.cnblogs.com/zfc2201/p/2152681.html
Copyright © 2011-2022 走看看