补充:在读取数据库上面还有一段helloworld的代码,已经可以运行了.完整的代码是:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;public class HelloWorldExample extends HttpServlet { public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter(); out.println("<html>");
out.println("<head>"); String title = rb.getString("helloworld.title"); out.println("<title>red_hello</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<h1>red</h1>");
out.println("<h1>");
try{
Class.forName("sun.jdbc.odbc.JbdcOdbcDriver");
Connection conn =
DriverManager.getConnection("jdbc:odbc:Customers");
Statement stmt =conn.createStatement();
String strSQL="select companyname from company";
ResultSet rs=stmt.executeQuery(strSQL);
ResultSetMetaData rsmd =rs.getMetaData();
int colcount=rsmd.getColumnCount();
int count=1;
while(rs.next())
{
out.println("<tr><td>");
String name=rs.getString(1);
out.println(name);
out.println("</td></tr>");
}//while
}catch(Exception e){
System.out.println(e);
}out.println("</h1>"); out.println("</body>");
out.println("</html>");
}
}页面显示的已经是"RED"了.
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;public class HelloWorldExample extends HttpServlet { public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter(); out.println("<html>");
out.println("<head>"); String title = rb.getString("helloworld.title"); out.println("<title>red_hello</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<h1>red</h1>");
out.println("<h1>");
try{
Class.forName("sun.jdbc.odbc.JbdcOdbcDriver");
Connection conn =
DriverManager.getConnection("jdbc:odbc:Customers");
Statement stmt =conn.createStatement();
String strSQL="select companyname from company";
ResultSet rs=stmt.executeQuery(strSQL);
ResultSetMetaData rsmd =rs.getMetaData();
int colcount=rsmd.getColumnCount();
int count=1;
while(rs.next())
{
out.println("<tr><td>");
String name=rs.getString(1);
out.println(name);
out.println("</td></tr>");
}//while
}catch(Exception e){
System.out.println(e);
}out.println("</h1>"); out.println("</body>");
out.println("</html>");
}
}页面显示的已经是"RED"了.
解决方案 »
- 求助:在服务器上部署的tomcat 服务器本机能访问 外面其他机器不能访问
- 关于liferay-portal-tomcat-6.0.4使用的问题
- TOMCAT:SQLNestedException 解决一例
- 已经无分可送 乱码问题
- 求JSP中request.getRealPath()和application.getRealPath()的详尽用法
- struts2 iterator标签 value值参数化的问题
- javascript找到了方法名找不到方法体,怎么回事?????
- 求救了,高手们!!!!
- bean的调用
- 小弟想去北京找工作,(JAVA)
- 使用自定义行为出现"未找到外部实体……”的错误
- 出了个异常奇怪的问题??
----------->
sun.jdbc.odbc.JdbcOdbcDriver以后细心点~~~~~~~~~~~~~~~~~
servlet全贴出来看看!!
stemp=rs.getString("companyname");
s2 = new String(stemp.getBytes("iso8859_1"),"GBK");
还有response.setContentType("text/html;charset=GBK"); 也不行.也试了.gb2312
还有iso8859_1到底是不是这样,我看也有人写iso8859-1.(不是下划线)都试了也不行.
明天就结贴.再试不出来我就找同学去了.真不好玩.