jsp和数据库连接大全
下面的jsp和数据库连接大全,请参考
一、jsp连接Oracle8/8i/9i数据库(用thin模式)
testoracle.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl为你的数据库的SID
String user="scott";
String password="tiger";
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()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
----------------------------------------------------------------------------------------------------------------
二、jsp连接Sql Server7.0/2000数据库
testsqlserver.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="";
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()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
注意: 要msutil.jar,mssqlserver.jar,msbase.jar
相关文档:
上网看了好多,就这一篇解决了我的问题,现转,我的项目用的是MVC架构,有统一的控制器,转向不同的Action,上网看了好多,大部分是说加入request.setCharacterEncoding("utf-8");但是经过我的试验,这只有在利用JSP处理表单传输数据时才可用,在我的东西中无法解决,后来发现还是用FilterChain好,呵呵,重点还是在request ......
pageEncoding
在JSP标准的语法中,如果pageEncoding属性存在,那么JSP页面的字符编码方式就由pageEncoding决定,否则就由contentType属性中的charset决定,如果charset也不存在,JSP页面的字符编码方式就采用默认的ISO-8859-1。
ContentType
ContentType属性指定了MIME类型和JSP页面回应时的字符编码方式。MIME类型的 ......
在WEB应用中,如果使用jsp作为view层的显示模板,都会被空格/空换行问题所困扰.
这个问题当年也困扰了我比较长的时间.因为在jsp内使用的EL标签和其他标签时,会产生大量的空格和换行符.例如:
------- start ----------
<c:choose>
<c:when test="${fn:length(mainPageList)>1&}&q ......
这两天在为项目嵌入这个插件,搞得焦头烂额,成功插入了的,可是不知道什么问题,就是上传不了图片,竟然出现了这样的警告:WARN net.fckeditor.handlers.RequestCycleHandler - No property found for UserPathBuilder implementation! The 'DefaultUserFilesPath' will be used in the ConnectorServlet!
在网上找了半 ......
概述
Java Server Pages(JSP)使得我们能够分离页面的静态HTML和动态部分。HTML可以用任何通常使用的Web制作工具编写,编写方式也和原来的一样;动态部分的代码放入特殊标记之内,大部分以“<%”开始,以“%>”结束。
例如,下面是一个JSP页面的片断,如果我们用http://host/OrderConfirm ......