一个jsp连接mysql的简单例子
程序员文章站
2022-06-09 17:14:05
<%@ page contenttype="text/html;charset=gb2312"%><%@ page language="java" import=...
<%@ page contenttype="text/html;charset=gb2312"%>
<%@ page language="java" import="java.sql.*"%>
<%
string mysql(和php搭配之最佳组合)driver = "org.gjt.mm.mysql(和php搭配之最佳组合).driver";
string url = "jdbc:mysql(和php搭配之最佳组合)://localhost/hq";//连接
connection conn;
class.forname(mysql(和php搭配之最佳组合)driver);
conn = drivermanager.getconnection( url,"root","");//用户名与密码
if(conn==null){
system.out.println("get conn error");
}
statement stmt=conn.createstatement();
resultset rs=null;
rs=stmt.executequery("select * from news_art");
while(rs.next())
{//循环显示记录
%>
<a href=display.(sun企业级应用的首选)?id=<%=rs.getstring("id")%> target=_blank><%=rs.getstring("title")%></a>(<%=rs.getstring("times")%>)
<%="<br>"%>
<%
}
rs.close();
stmt.close();
conn.close();
%>
<%@ page language="java" import="java.sql.*"%>
<%
string mysql(和php搭配之最佳组合)driver = "org.gjt.mm.mysql(和php搭配之最佳组合).driver";
string url = "jdbc:mysql(和php搭配之最佳组合)://localhost/hq";//连接
connection conn;
class.forname(mysql(和php搭配之最佳组合)driver);
conn = drivermanager.getconnection( url,"root","");//用户名与密码
if(conn==null){
system.out.println("get conn error");
}
statement stmt=conn.createstatement();
resultset rs=null;
rs=stmt.executequery("select * from news_art");
while(rs.next())
{//循环显示记录
%>
<a href=display.(sun企业级应用的首选)?id=<%=rs.getstring("id")%> target=_blank><%=rs.getstring("title")%></a>(<%=rs.getstring("times")%>)
<%="<br>"%>
<%
}
rs.close();
stmt.close();
conn.close();
%>
上一篇: 手游更需要基于熟人的强碎片化社交系统