java¿ª·¢DB2³ÌÐò
1. JDBC Çý¶¯³ÌÐò
1.1 DB2 JDBC Type 2 Çý¶¯³ÌÐò
DB2 ¿Í»§»ú
²»½¨ÒéʹÓÃ
COM.ibm.db2.jdbc.app.DB2Driver µ÷ÓÃClass.forName() ·½·¨¡£
1.2 IBM DB2 ͨÓÃJDBC ºÍSQLJ Çý¶¯³ÌÐò
ÌṩÁËType 2 Á¬½ÓÐÔºÍType 4 Á¬½ÓÐÔ
¿ÉÒÔ½«Õâ¸öÇý¶¯³ÌÐòÓÃÓÚapplet ºÍÓ¦ÓóÌÐò
com.ibm.db2.jcc.DB2Driver µ÷ÓÃClass.forName() ·½·¨¡£
2. ½¨Á¢Êý¾Ý¿âÁ¬½Ó
import java.sql.*; Í·Îļþ
String url = "jdbc:db2:sample"; TYPE 2
String url = "jdbc:db2:sample://localhost:50000"; TYPE4
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection con = DriverManager.getConnection(url);
3. Statement ¶ÔÏó
Statement ¶ÔÏóÊÇʹÓÃConnection.createStatement() ·½·¨´´½¨µÄ
Statement stmt;
stmt = con.createStatement();
stmt.executeUpdate("DELETE from EMPLOYEE WHERE EMPNO = '000099'");
ResultSet rs;
rs = stmt.executeQuery("SELECT EMPNO, LASTNAME from EMPLOYEE");
while (rs.next()) {
System.out.println(rs.getString(1) + ", " + rs.getDate(2));
}
4. PreparedStatement ¶ÔÏó
PreparedStatement ¶ÔÏóÊÇʹÓÃConnection.prepareStatement() ·½·¨´´½¨µÄ
pStmt = con.prepareStatement("UPDATE STAFF SET COMM=? WHERE ID=?");
pStmt.setDouble(1,710.53);
pStmt.setInt(2,350);
pStmt.executeUpdate();
5. Ìá½»ÊÂÎñ
con.setAutoCommit(true); ×Ô¶¯Ìá½»
con.commit(); ...
con.rollback();
Ö´Ðзֲ¼Ê½ÊÂÎñ
DB2XADataSource db2ds = new com.ibm.db2.jcc.DB2XADataSource();
6.¿ª·¢SQLJ Ó¦ÓóÌÐò(¾²Ì¬sql)
6.1 Ìí¼ÓÍ·Îļþ
import sqlj.runtime.*; Í·Îļþ
import java.sql.*; Í·Îļþ
6.2 ½¨Á¢Á¬½ÓÉÏÏÂÎÄ
#sql context Ctx;
String url = " jdbc:db2:sample://localhost:50000"; TYPE 4
Class.forName("com.ibm.db2.jcc.DB2Driver");
Ctx connCtx = new Ctx(url,true);
String url = " jdbc:db2:sample”; TYPE 2
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
6.3 ·¢³öSQL Óï¾ä
Ïà¹ØÎĵµ£º
Ô´´úÂ룺
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class brandishString extends Applet implements Runnable, MouseListener {
String str; // ÒªÏÔʾµÄ×Ö·û ......
ÆäʵʹÓÃmavenÒѾºÜ¾ÃÁË£¬´ÓÔçÆÚµÄ1.0.1µ½ÏÖÔÚµÄ2.0.6£¬Æäʵ¶ÔÓÚÒ»°ãÏîÄ¿¿ª·¢£¬³£ÓõÄÒ²¾ÍÊÇ´´½¨ÏîÄ¿(Create)¡¢¹¹½¨(Build)¡¢²âÊÔ(Test)¡¢·¢²¼(Release)¡£±¾ÎIJ¢²»ÊǹØÓÚmavenÈçºÎʹÓõÄÏêϸ½éÉÜ£¬¶øÖ»ÊÇÔÚʵ¼ÊÏîÄ¿¿ª·¢ÖеÄһЩ³£ÓûÒÔ¼°Ïà¹Ø²å¼þµÄʹÓÃ×ܽᣬÈç¹ûÄã¶ÔÓÚmavenÉв»Á˽⣬¿ÉÒÔÏÈÔÚ¹Ù·½ÍøÕ¾[Maven'site]¹ä¹ ......
»Øµ÷¸ÅÄî:
Èí¼þÄ£¿éÖ®¼ä×ÜÊÇ´æÔÚ×ÅÒ»¶¨µÄ½Ó¿Ú£¬´Óµ÷Ó÷½Ê½ÉÏ£¬¿ÉÒÔ°ÑËûÃÇ·ÖΪÈýÀࣺͬ²½µ÷Óᢻص÷ºÍÒì²½µ÷Óá£Í¬²½µ÷ÓÃÊÇÒ»ÖÖ×èÈûʽµ÷Ó㬵÷Ó÷½ÒªµÈ´ý¶Ô·½Ö´ÐÐÍê±Ï²Å·µ»Ø£¬ËüÊÇÒ»ÖÖµ¥Ïòµ÷Ó㻻ص÷ÊÇÒ»ÖÖË«Ïòµ÷ÓÃģʽ£¬Ò²¾ÍÊÇ˵£¬±»µ÷Ó÷½ÔÚ½Ó¿Ú±»µ÷ÓÃʱҲ»áµ÷ÓöԷ½µÄ½Ó¿Ú£»Òì²½µ÷ÓÃÊÇÒ»ÖÖÀàËÆÏûÏ¢»òʼþµÄ»úÖÆ£¬² ......
½ñÌì·¢ÏÖÒ»¸öºÜNBµÄÍæÒ⣬ÈÃÎÒÃÇÔÚ¿ª·¢µÄʱºòÐÞ¸ÄJavaÎļþ£¬²»ÓÃÖØÆô·þÎñÆ÷Á¢¿ÌÉúЧ£¡Ö§³ÖJetty tomcat jbossµÈºÜ¶à·þÎñÆ÷£¬Ëü¾ÍÊÇJRebel¡£ http://www.zeroturnaround.com/jrebel/installation/ ÕâÀïÓÐÕë¶Ô²»Í¬·þÎñÆ÷µÄ°²×°·½·¨£¬»ù±¾ÉÏÖ÷Á÷µÄ¶¼º¸ÇÁË£¬¾ø´ó¶àÊý³ÌÐòÔ±¶¼ÄÜʹÓã¡ÎÒÃǹ«Ë¾ÓÃmaven/jetty¶ÔÏîÄ¿½øÐй¹½¨ºÍ¿ª ......