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连接失败!");
    		}
    
    	}
    
    }
    
  • 相关阅读:
    linux ioctl
    pkg-config用法和gcc cflags
    boost noncopyable类
    google protobuf使用2
    跨平台编译CMake使用
    Linux epoll
    docker安装
    python 脚本转成exe可执行程序
    shell相关知识
    tcpdump使用
  • 原文地址:https://www.cnblogs.com/wangxueliang/p/9346467.html
Copyright © 2011-2022 走看看