首页 > 数据库技术 > 详细

JSP数据库连接成功

时间:2018-08-08 00:14:44      阅读:218      评论:0      收藏:0      [点我收藏+]
<%@ page language="java" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%>
<%@ page  import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
    PreparedStatement ps = null;
    Connection ct = null;
    ResultSet rs = null;
    String url = "jdbc:sqlserver://localhost:1433;databaseName=test";
    String user="sa";  //超级管理员
    String password="sa";  //密码
    try {
        //1.加载驱动
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        System.out.println("加载驱动成功!");
    }catch(Exception e) {
        e.printStackTrace();
        System.out.println("加载驱动失败!");
    }
    try {  
        //2.连接
        ct=DriverManager.getConnection( url,user,password);
        System.out.println("连接数据库成功!");
    }catch(Exception e) {
        e.printStackTrace();
        System.out.println("连接数据库失败!");
    }
    
      
    
     %>
</body>
</html>

 

JSP数据库连接成功

原文:https://www.cnblogs.com/borter/p/9440392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!