架设贫民化企业级网站jsp+tomcat+postgresql
架设贫民化企业级网站jsp+tomcat+postgresql
步骤:
1.安装jdk (j2sdk1.4.1_02)
2.安装Tomcat
3.添加环境变量(包括用户、系统):
classpath C:\j2sdk1.4.1_02\lib\tools.jar;C:\j2sdk1.4.1_02\lib\dt.jar
JAVA_HOME C:\j2sdk1.4.1_02
path C:\j2sdk1.4.1_02\bin
5、下载jar文件,例如:postgresql-8.1dev-400.jdbc3.jar (jdbc for pg)
(http://jdbc.postgresql.org/download.html)
4、数据库连接
将postgresql-8.1dev-400.jdbc3.jar文件拷贝到\jre\lib\ext目录下,并且重新启动Apache Tomcat
5、建立pgtest.jsp文件进行测试:http://localhost:8080/pgtest.jsp
<%="hi pg"%>
<%@ page import="java.sql.*"%>
<%
Class.forName("org.postgresql.Driver").newInstance();
Connection conn= DriverManager.getConnection("jdbc:postgresql://localhost/test","postgres","123456");
Statement stmt=conn.createStatement();
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
%>