<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.net.*"%>
<%@page import="java.text.*"%><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<jsp:useBean id="tools" class="tool.ToolBox"/>
<title>test</title>
</head><body bgcolor="#7B0000" text="#FFFF00" vlink="#663399" alink="#FF0000">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="181" height="232" valign="top">
<table width="100%" height="202" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="28%"><font color="#333399"><b><img src="image/win.gif" width="14" height="11" /><font color="#FFFF00">论坛公告:</font></b></font></td>
<td width="72%"> <marquee width="100%" height="100%" direction="up">
<%
Connection con = tools.getConn ();
Statement stmt = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select title,post_date,content from bulletin_info order by id desc";
String Notice="";
int i=0; //Number of messages to be shown in bulletin message bar
ResultSet rs = stmt.executeQuery(sql);
while ((rs.next()) && (i<5))
{
String Time=rs.getString("post_date");
Time=Time.substring(5,16);
Notice="<B>"+tools.ex_chinese(rs.getString("title"))+":</B>" +
"<font color=black>"+tools.ex_chinese(rs.getString("content"))+"</font>" +
"<font color=gray> "+Time+"</font> " +
Notice;
i++;
}
out.println(Notice);
%>
</marquee> </td>
</tr>
</table>
<p> </p></td>
<td width="569" valign="top"> </td>
</tr>
</table>
<br />
</body>
</html>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.net.*"%>
<%@page import="java.text.*"%><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<jsp:useBean id="tools" class="tool.ToolBox"/>
<title>test</title>
</head><body bgcolor="#7B0000" text="#FFFF00" vlink="#663399" alink="#FF0000">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="181" height="232" valign="top">
<table width="100%" height="202" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="28%"><font color="#333399"><b><img src="image/win.gif" width="14" height="11" /><font color="#FFFF00">论坛公告:</font></b></font></td>
<td width="72%"> <marquee width="100%" height="100%" direction="up">
<%
Connection con = tools.getConn ();
Statement stmt = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select title,post_date,content from bulletin_info order by id desc";
String Notice="";
int i=0; //Number of messages to be shown in bulletin message bar
ResultSet rs = stmt.executeQuery(sql);
while ((rs.next()) && (i<5))
{
String Time=rs.getString("post_date");
Time=Time.substring(5,16);
Notice="<B>"+tools.ex_chinese(rs.getString("title"))+":</B>" +
"<font color=black>"+tools.ex_chinese(rs.getString("content"))+"</font>" +
"<font color=gray> "+Time+"</font> " +
Notice;
i++;
}
out.println(Notice);
%>
</marquee> </td>
</tr>
</table>
<p> </p></td>
<td width="569" valign="top"> </td>
</tr>
</table>
<br />
</body>
</html>
解决方案 »
- SSH上传 jsp空间 运行404
- java中oracle数据Date显示问题!!经验老到者来!!
- 如何把JSP页面的URL参数传到JAVA后台去???
- URLEncoder问题
- 招聘java中高级程序员
- 为什么我执行两次数据库操作TOMCAT就会断掉
- 我把Tomcat整合到IIS里,不再需要8080端口来访问站点.但我的servlet还得用8080来访问,怎么办?
- linux下export不能执行!!
- 怎样在jsp网业中保存住我的checkbox的选项.
- 看来搞 JSP/Servlet/JavaBean的人还真多,每天的新贴都占了好几页,再看看别的版块,一天就那么几贴,赶潮流啊,都是一窝蜂,实在令人感
- 关于web打印的问题!!!
- 郁闷啊,我的服务器到底怎么了,高手帮助我啊
///////////////////////////////////////////////////////////
//function:
//1) get connection from the forum database which is base on
// jdbc-odbc connection bridge, and return the ronncetion.
//2) format the given string into chinese GBcode
//3) get the current time and return as a string
///////////////////////////////////////////////////////////package tool;import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;public class ToolBox
{
private Connection conn; //construction
public ToolBox ()
{
} //get connection from database
public Connection getConn ()
{
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection ("jdbc:odbc:forum");
} catch (Exception e) {
e.printStackTrace ();
System.out.println ("Database Connection Encounted an Exception" + e.getMessage());
}
return conn;
} //change the string into chinese GBcode
public String ex_chinese (String str)
{
if (str == null) {
str = "";
}
else {
try {
str = new String (str.getBytes ("iso-8859-1"), "gb2312");
} catch (Exception ex) {
}
}
return str;
} //get the current time and return as a string
public String getcurrTime ()
{
String datestr = "";
try {
DateFormat df = new SimpleDateFormat ("yyyy-M-d HH:ss");
java.util.Date date = new java.util.Date ();
datestr = df.format (new java.util.Date ());
} catch (Exception ex) {
}
return datestr;
}
}
but i havn't set the username and password when i create my database.
which name and password should i use?
Could you just try to set them and provide them in java code, first?
here is my testing:
when i change the centence in my jsp file:
Notice = "<B>"+tools.ex_chinese(rs.getString("title"))+":</B>" +
"<font color=black>"+tools.ex_chinese(rs.getString("content"))+
"</font>" + "<font color=gray> "+Time+"</font> "
+ Notice;into:Notice = "<font color=black>"+tools.ex_chinese(rs.getString("content"))+
"</font>" +
"<font color=gray> "+Time+"</font> " + Notice;it can runs normally. but when i convert it into the former one, it was encount an exception which was shown above.
of course, i've tried to set the username and password before my testing, but i'm sure my connection between my jsp file and database, because i'd connected the database sucessfully for many times!
can you tell me why did it encount the miracle exception?
thanks!!!!!!!!!!
Statement stmt = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);It is the most flexible mode, if it works, you can narrow down till the best performance reached