--方法一 使用java web 在jsp文件中连接 连接MySQL的驱动
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'index.jsp' starting pagetry{
Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动,注册到驱动管理器
String URL="jdbc:mysql://localhost:3306/test";//数据库连接字符串 localhost表示本机也可以用IP地址或者计算机的名字 3306表示服务端口 test表示数据库的名称
String username="惜忆隐蝶"; //数据库用户名
String password="123"; //数据库密码 123
// Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","惜忆隐蝶","123");//方式一
Connection cn=DriverManager.getConnection(URL, username, password);//方式二
//创建Connection连接
if(cn !=null){ //判断数据库连接是否成功
out.println("数据库连接成功!"); //输出连接信息
cn.close(); //关闭数据库连接
}else{
out.println("数据库连接失败!"); //输出连接信息
cn.close(); //关闭数据库连接
}
}catch(ClassNotFoundException e){
e.printStackTrace();
out.println(e.toString()+"
驱动类无法加载!");
}catch(SQLException e){
e.printStackTrace();
out.println(e.toString()+"
数据库连接不上!");
}
%>
---方法一 使用java web 在jsp文件中连接 连接SQLsever的驱动
String path = request.getContextPath();
String basePath = requ