开发者社区 问答 正文

关于加载SQL server数据库驱动

screenshot
我下载的是SQL server2008,然后创建了一个数据库hospital,穿件了一张表,然后我在网上下载了一个jar包加到bin目录下面了,然后在eclipse里面用java程序链接数据可是加载失败,这是为什么啊

展开
收起
蛮大人123 2016-03-25 15:20:54 2921 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    SQL Server 2008
    相应改下用户名,密码,数据库名

     public static Connection getConnection(){
        String url="jdbc:sqlserver://localhost:1433;DataBeseName=flower";
        String user="Flowershop";
        String pwd="Flowershop";
        Connection conn=null;
        try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        }catch(ClassNotFoundException e){
        System.out.println(e);
        }
        try{
         conn=DriverManager.getConnection(url,user,pwd);
         }catch(SQLException e){
         System.out.println(e);
         }
         return conn;
         }
    public boolean  executesql(String sql){
         Connection conn=getConnection();
         boolean flag=false;
         Statement stmt=null;
         try{
         stmt=conn.createStatement();
         stmt.executeUpdate(sql);
         flag=true;
         }catch(Exception e)
         {
            e.printStackTrace();
        }finally{
            close(stmt,conn);
            }
            return flag;
            }
    2019-07-17 19:14:29 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等