<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<body bgcolor="#bbccvv">
<center><%
request.setCharacterEncoding("gbk");
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test");
Statement stmt = conn.createStatement();
String sql = "select * from person";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
out.print("\t ID:"+ rs.getString(1));
out.print( "\t tel:"+ rs.getString(2));
out.print("\t address:"+ rs.getString(3));
out.println();
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
</center>
你好,欢迎您的到来!
</body>
</html>
这是一个通过JSP来连接数据库的页面,可为什么总是不显示出数据库的内容呢,在哪位朋友知道的话,请指教下谢谢,我的QQ是274409357
为什么Microsoft SQL Server连接起来了却在页面上显示不出来
答案:1 悬赏:70 手机版
解决时间 2021-02-23 19:42
- 提问者网友:雪舞兮
- 2021-02-23 12:07
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-02-23 13:11
我稍微改动了一下,如下:(好像是连接语句中少了,用户名和密码)
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<body bgcolor="#bbccvv">
<center><%
request.setCharacterEncoding("gbk");
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test","sa",""); //////这里少了用户名密码,sa是我假设的
Statement stmt = conn.createStatement();
String sql = "select * from person";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
out.print("\t ID:"+ rs.getString(1));
out.print( "\t tel:"+ rs.getString(2));
out.print("\t address:"+ rs.getString(3));
out.println();
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
</center>
你好,欢迎您的到来!
</body>
</html>
你再试一下!!!!!!!!
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<body bgcolor="#bbccvv">
<center><%
request.setCharacterEncoding("gbk");
try {
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test","sa",""); //////这里少了用户名密码,sa是我假设的
Statement stmt = conn.createStatement();
String sql = "select * from person";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
out.print("\t ID:"+ rs.getString(1));
out.print( "\t tel:"+ rs.getString(2));
out.print("\t address:"+ rs.getString(3));
out.println();
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
%>
</center>
你好,欢迎您的到来!
</body>
</html>
你再试一下!!!!!!!!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯