我下载的是SQL server2008,然后创建了一个数据库hospital,穿件了一张表,然后我在网上下载了一个jar包加到bin目录下面了,然后在eclipse里面用java程序链接数据可是加载失败,这是为什么啊
关于加载SQL server数据库驱动
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- zhituji 2015-12-21 13:52关注
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; }
解决 无用评论 打赏 举报