JAVA JDBC·ÃÎÊÊý¾Ý¿â±ê×¼´úÂë
package edu.zzu.jdbc.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.ambow.jdbc.entity.Student;
public class TestDBConn{
public static void main(String args[]){
String url="jdbc:sqlserver://localhost:1433;databaseName=zzu";
String username="sa";
String password="123456";
Connection conn =null;
Statement stmt =null;
ResultSet rs =null;
try {
//1¡¢¼ÓÔØÇý¶¯
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//2¡¢Í¨¹ýDriverManagee»ñÈ¡Á¬½Ó°üÀ¨(Êý¾Ý¿âÁ¬½Ó×Ö·û´®,Óû§Ãû,ÃÜÂë)
conn = DriverManager.getConnection(url, username, password);
//3¡¢Í¨¹ý Connection ¶ÔÏóÀ´´´½¨ createStatement
stmt = conn.createStatement();
//4¡¢×Ô¶¨Òå SQL Óï¾ä
// String sql = " select * from student ";
String sql = "insert into student values (?,?,?) ";
//5¡¢Í¨¹ý statement ¶ÔÏóÀ´Ö´ÐÐ SQL Óï¾ä£¬²¢ÇÒ·µ»Ø½á¹û¸ø ResultSet
rs =stmt.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getInt("id")+" ");
System.out.print(rs.getString("name")+" ");
System.out.println(rs.getString("password"));
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try{
if(conn!=null){
conn.close();
conn=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
&n
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
¹Ø¼ü×Ö: filter
¹ýÂËÆ÷FilterÒ²¾ßÓÐÉúÃüÖÜÆÚ£ºinit()->doFilter()->destroy()£¬Óɲ¿ÊðÎļþÖеÄfilterÔªËØÇý¶¯¡£ÔÚservlet2.4ÖУ¬¹ýÂËÆ÷ͬÑù¿ÉÒÔÓÃÓÚÇëÇó·ÖÅÉÆ÷£¬µ«ÐëÔÚweb.xmlÖÐÉùÃ÷£¬<dispatcher>INCLUDE»òFORWARD»òREQUEST»òERROR</dispatcher>¸ÃÔªËØλÓÚfilter-mappingÖС£
Ò»¡ ......
//¼òµ¥µÄjavaÈÕÆÚ¸ñʽ¿ØÖÆ
java.Text.SimpleDateFormat format = new java.Text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//ÄãÏëÒªµÄ¸ñʽ
//×¢ÒâÔµÄλÖÃÒª´óдµÄMM Òª²»¾Í¿´µ½µÄ²»ÊÇÕýÈ·ÏÔʾ£¬¿ÉÒÔ°ÑÄãÏëҪת»»µÄÈÕÆÚת»»ÎªÏàÓ¦µÄ¸ñʽ°¡
format.format(new java.util.Date());//dateΪÈÕÆÚÐÍÊý¾Ý£¬¿ÉÒÔÈÎÒ ......
ÎÊÌâÓò:
--ϵͳÖÐÄãÐèÒª»ñµÃij¸öÀàµÄΨһʵÀý£¬ËùÓпͻ§¶Ë¶ÔËüµÄ·ÃÎʶ¼½«Í¨¹ýÒ»¸ö¹«¹²µÄ·ÃÎʵã»ñµÃ
--´´½¨Ò»¸öÀಢʹÆ䣺(A)¶¨ÒåÒ»¸ö˽ÓеĹ¹ÔìÆ÷£¨B£©¶¨ÒåÒ»¸ö˽ÓС¢¾²Ì¬µÄ±äÁ¿Ö¸Ïò×Ô¼º£¨C£©¶¨ÒåÒ»¸ö¹«ÓС¢¾²Ì¬µÄ·ÃÎÊ·½·¨ÓÃÓÚ·µ»Ø¸ÃÀàµÄÒ»¸öΨһʵÀý
·ÖΪ ¶öººÊ½ ºÍ ÀÁººÊ½,ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄʾÀý´úÂ룬Ӧ¸Ã ......