zoukankan      html  css  js  c++  java
  • Eclipse连接SQLServer,进行增加操作

    文章参考自:https://blog.csdn.net/vs_the_old_boy/article/details/52596350

    package jdbc;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    public class SqlServerConnect {
    	public static void main(String[] args) {
    		String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    		String dbURL = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test1";
    		String sql="insert into Table_1 values('50','张三风','男')";
    		//String sql="select * from Table_1";
    		String userName = "1141265442";
    		String userPwd = "*******";
    		
    		//加载数据库驱动
    		try {
    			Class.forName(driverName);
    			System.out.println("加载驱动成功!");
    		} catch (Exception e) {
    			e.printStackTrace();
    			System.out.println("加载驱动失败!");
    		}
    		
    		try {
    			//获得数据库连接
    			Connection dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
    			System.out.println("连接数据库成功!");
    			
    			//获得语句执行的对象
    			Statement stmt= dbConn.createStatement();
    			
    			//执行语句
    			ResultSet rs = stmt.executeQuery(sql);//创建数据对象
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    			System.out.print("SQL Server连接失败!");
    		}
    
    	}
    
    }
    
  • 相关阅读:
    Nosql database
    NoSQL
    nodejs and db
    Nodejs and json
    Nodejs异步
    HTTP-304 NOT Modified
    Origin null is not allowed by Access-Control-Allow-Origin
    nodejs MVC
    solr 亿万级数据查询性能測试
    iOS8 对开发人员来说意味着什么?
  • 原文地址:https://www.cnblogs.com/wangxueliang/p/9346467.html
Copyright © 2011-2022 走看看