Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JSPʵÀýÒ»¡¢¹ºÎï³µ


֪ʶ׼±¸£º
JDBC·ÃÎÊÊý¾Ý¿âµÄ»ù±¾²½Öè
£¨1£©¡¢½«Êý¾Ý¿âµÄJDBCÇý¶¯¼ÓÔص½¹¤³ÌÀà¿âÖС£
£¨2£©¡¢¼ÓÔØJDBCÇý¶¯£¬²¢½«Æä×¢²áµ½DriverManagerÖС£ÏÂÃæÊÇһЩÖ÷Á÷Êý¾Ý¿âµÄJDBCÇý¶¯¼ÓÔØ×¢²áÂ룺
¢Ù¡¢oracleÊý¾Ý¿â
Class.forName(“oracle.jdbc.driver.OracleDriver”).newInstance();
¢Ú¡¢Sql Server 7.0/2000Êý¾Ý¿â
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”).newInstance();
¢Û¡¢MySQLÊý¾Ý¿â
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
(3)¡¢½¨Á¢Êý¾Ý¿âÁ¬½Ó£¬È¡µÃConnection¶ÔÏó¡£
¢Ù¡¢oracleÊý¾Ý¿â
String url=”jdbc:oracle:thin:@localhost:1521:orcl”;
String user=”scott”:
String password=”tiger”;
Connetion conn=DriverManager.getConnetion(url,user,password);
¢Ú¡¢Sql Server 7.0/2000Êý¾Ý¿â
String url=”jdbc:microsoft:sqlserver://localhost:1443;DatabaseName=pubs”;
String user=”sa”;
String password=””;
Connection conn=DriverManager.getConnection(url,user,password);
¢Û¡¢MySQLÊý¾Ý¿â
String url=”jdbc:mysql://localhost:3306/testDB?user=root&password=root&
useUnicode=true&charaterEncoding=gb2312”;
Connection conn=DriverManager.getConnection(url);
(4)¡¢½¨Á¢Statement¶ÔÏó»òPreparedStatement¶ÔÏó¡£
//½¨Á¢Statement¶ÔÏó
Statement stmt=conn.createStatement();
//½¨Á¢PreparedStatement¶ÔÏó
String sql=”select *from users where userName=? And password=?”;
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,”admin”);
pstmt.setString(2,”liubin”);
(5)¡¢Ö´ÐÐSQLÓï¾ä¡£
//Ö´Ðо²Ì¬SQL²éѯ
String sql=”select * from users”;
ResultSet rs = stmt.executeQuery(sql);
//Ö´ÐÐinsert¡¢update¡¢deleteµÈÓï¾ä£¬Ïȶ¨Òåsql
Stmt.executeUpdate(sql);
(6)¡¢·ÃÎʽá¹û¼Ç¼¼¯ResultSet¶ÔÏó¡£
While(rs.next())
{
    out.println(“ÄãµÄµÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º“+rs.getString(1));
    out.println(“ÄãµÄµÚ¶þ¸ö×Ö¶ÎÄÚÈÝΪ£º“+rs.getString(2));
}
(7)¡¢ÒÀ´Î½«ResultSe


Ïà¹ØÎĵµ£º

JSPÒ³Ãæµ÷ÓÃjsÖÐÎÄÂÒÂë

jspÖеÚÒ»¾ä£º
<%@ page language="java" import="java.sql.*,java.util.*,"  contentType="text/HTML;charset=gb2312" pageEncoding="gb2312"%>
htmlÖмÓÉÏ
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
ͨ³£ÕâÑù¾ÍûÓÐÎÊÌâÁË¡£    .
ÔÙÕߣº µ¼ÈëjsʱºòÉ ......

JSPÖÐÓë·¾¶Ïà¹ØµÄ³£Óõļ¸¸ö·½·¨


http:/localhost/123/jsp/test.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logi ......

jspµ÷Óô洢¹ý³Ì

  ÔÚsql2000Öд´½¨´æ´¢¹ý³Ì£º
--ÇóÁ½ÊýÖ®ºÍ
create proc up_sum @a int ,@b int ,@result int output
as
select @result= @a+@b
µ÷Ó÷½·¨£º
...
CallableStatement cstmt=con.prepareCall("exec  up_sum ?,?,?");
cstmt.registerOutParameter(3,java.sql.Types.INTEGER);
    &nb ......

jspÖ®session

     session¾ÍÊÇÒ»¸öÈ«¾Ö±äÁ¿£¬ÊÇä¯ÀÀÆ÷Ïß³ÌÔÚ·þÎñÆ÷¶ËµÄ´úÀí¡£web·þÎñ³ÌÐòÖ»Òª´ò¿ª£¬session¾Í»á´æÔÚ£¬µ±ÄãµÚÒ»´Î·ÃÎÊʱ£¬session»á×Ô¶¯ÎªÄã·ÖÅäÒ»¸ösession ID£¬ËùÒÔsessionΪн¨Á¢µÄ£¬ËùÒÔsession.isNew()Ϊtrue¡£µ±ÄãË¢ÐÂÒ³Ãæʱ£¬Õâ¸ösession IDÒ»Ö±´æÔÚ(session.getId()²»±ä)£¬²»»áÏûʧ£¬ËùÒÔse ......

JSP±àÂ볣ʶ[ת]

GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍwcscmp()µÄ·µ»Ø½ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ