JSP連接各類數(shù)據(jù)庫(kù)大全(7)
發(fā)表時(shí)間:2024-02-03 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]七、jsp連接PostgreSQL數(shù)據(jù)庫(kù) testmysql.jsp如下: <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*&quo...
七、jsp連接PostgreSQL數(shù)據(jù)庫(kù) testmysql.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/soft"
//soft為你的數(shù)據(jù)庫(kù)名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一個(gè)字段內(nèi)容為:<%=rs.getString(1)%>
您的第二個(gè)字段內(nèi)容為:<%=rs.getString(2)%>
<%}%>
<%out.print("數(shù)據(jù)庫(kù)操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>