问题描述
- 在myeclipse配置tomcat 连接sql数据库
-
有错运行不了错误提示是The server encountered an internal error () that prevented it from fulfilling this request
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
/* String sql=""; /
String str==null?"":str;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();/ 获取 驱动*/String userName="root"; String password="123"; sql="SELECT*FROM books"; conn=DriverManager.getConnection("jdbc:mysql://loclhost:3306/test",userName,password);/* 连接数据库*/ statement=conn.createStatement();/* 通过connection数据库链接对象 创建一个statement对象数据库操作对象 */ rs=statement.executeQuery(sql);
out.print("
");
out.print("
");
out.print(""+"id");
out.print(""+"bookname");
out.print(""+"bookwriter");
out.print(""+"publisher");
out.print(""+"type");
out.print(""+"price");
out.print("");
while(rs.next())
{
out.print("
");
out.print(""+rs.getString(1)+" ");
out.print(""+rs.getString(2)+" ");
out.print(""+rs.getString(3)+" ");
out.print(""+rs.getString(4)+" ");
out.print(""+rs.getString(5)+" ");
/* out.print(""+rs.getString(6)+" "); */
out.print("</TR>"); } out.print("</Table>"); conn.close();
} catch(SQLException e1){
out.print("error sqlException!");
}
%>
解决方案
1、在Myeclipse中启动已有项目时,如果项目是直接拷贝到本机上,加载workbench后里面的Package
Explore没有任何包文件,如图:
?
2.在Package Explore中右键->new->选择Java Project,在Project name一栏中输入原项目名字。于是原项目中的代码和网页文件就会自动导入到Package Explore中:
3.然后配置......
答案就在这里:Myeclipse配置Tomcat 以及连接数据库
----------------------