ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

ÎÒʵÏÖµÄÄÚ´æÊý¾Ý¿âJDBCÇý¶¯(Îå)
2015-07-24 10:56:07 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:5´Î
Tags£ºÊµÏÖ ÄÚ´æ Êý¾Ý¿â JDBC Çý¶¯
tion { return new LxjDbStatement(this); } } 3¡¢StatementÀà

Ö÷ҪʵÏÖÁ½¸ö·½·¨£¬Ò»ÊÇÖ´ÐÐûÓнá¹û¼¯·µ»ØµÄexecuteUpdate()·½·¨£¬ÈçÖ´ÐÐupdate, delete, insertÒ»ÀàµÄsqlÓï¾ä£»

¶þÊÇÖ´ÐÐselect²éѯÓï¾äµÄResultSet executeQuery(String sql)·½·¨£¬ÏÔÈ»£¬Õâ¸ö·½·¨½«·µ»Ø½á¹û¼¯¡£

package com.lxjdb.jdbc;

import java.sql.*;

public class LxjDbStatement implements java.sql.Statement {
	public LxjDbConnection conntion;
	public LxjDbApi lxjdb;
	public long conn;
	
	public LxjDbStatement(LxjDbConnection pconn){
		conntion = pconn;
		lxjdb = pconn.lxjdb;
		conn = pconn.conn;
	}
	public ResultSet executeQuery(String sql) throws SQLException {
		String[] dbInfo = new String[1];
		int ret = lxjdb.Exec(conn, sql, dbInfo);
		if(ret<0){
			throw new SQLException(dbInfo[0]);
		}
		
		return new LxjDbResultSet(conntion);
	}
	
	public int executeUpdate(String sql) throws SQLException {
		String[] dbInfo = new String[1];
		int ret = lxjdb.Exec(conn, sql, dbInfo);
		if(ret<0){
			throw new SQLException(dbInfo[0]);
		}
		return ret;
	}
}
4¡¢ResultSetÀà

´¦Àí½á¹û¼¯¡£ÎÒÃǵÄÄÚ´æ Êý¾Ý¿â±È½Ï¼ò»¯£¬·µ»ØµÄÊý¾Ý¶¼ÊÇ×Ö·û´®ÀàÐÍ£¬Òò´ËֻҪʵÏÖgetString()£¬ÆäËüʲôgetInt(), getLong(), getDouble()Ö®ÀàµÄÊý¾ÝÀàÐ;Ͳ»ÓèʵÏÖÁË¡£

µ±È»£¬»¹ÒªÊµÏÖÒÆ¶¯½á¹û¼¯ÓαêÐÐÖ¸ÕëµÄһЩ·½·¨¡£

package com.lxjdb.jdbc;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.Map;
public class LxjDbResultSet implements java.sql.ResultSet {
	public LxjDbApi lxjdb;
	public long conn;
	public LxjDbResultSet(LxjDbConnection pconn){
		lxjdb = pconn.lxjdb;
		conn = pconn.conn;
	}
	
	public boolean next() throws SQLException {
		int ret = lxjdb.Next(conn);
		return ret>0 ? true : false;
	}

	public boolean first() throws SQLException {
		if(lxjdb.Rows(conn)<1)
			return false;
		
		int ret = lxjdb.GotoRec(conn, 1);
		return ret>0 ? true : false;
	}
	
	public boolean last() throws SQLException {
		int r = lxjdb.Rows(conn);
		if(r<1)
			return false;
		
		int ret = lxjdb.GotoRec(conn, r);
		return ret>0 ? true : false;
	}
	
	public String getString(int columnIndex) throws SQLException {
		String[] retVal = new String[1];
		lxjdb.GetValByIndex(conn, columnIndex-1, retVal);  // columnIndexÊÇ´Ó1¿ªÊ¼µÄ
		return retVal[0];
	}

	public String getString(String columnLabel) throws SQLException {
		String[] retVal = new String[1];
		lxjdb.LxjDbGetValByName(conn, columnLabel, retVal);
		return retVal[0];
	}
	
	public int getFetchSize() throws SQLException {	
		return lxjdb.Rows(conn);
	}
}

µÚÈý²½£¬±àÒëºóµ¼³öΪjarÎļþ£º

ÔÚEclipse϶Ô×¼ÏîÄ¿ÓÒ¼ü£¬Ñ¡Ôñ¡°Export...¡±£¬µ¼³öLxjDbJdbc.jar¡£

ÕâÑù¾Í³É¹¦µØÊµÏÖÁËjdbcÇý¶¯¡£

ÏÂÃæÔپͿÉÒÔ½øÐвâÊÔÁË¡£

µÚËIJ½£¬²âÊÔ£º

²âÊÔ´úÂë±È½Ï¼òµ¥£¬²»Óùý¶à½âÊÍ£º

import java.sql.*;

public class JdbcTest {

	public static void main(String[] args) {
		String driver = "com.lxjdb.jdbc.Driver";
        String userName = "sa";
        String passwrod = "********";
        String url = "jdbc:lxjdb://192.168.0.106:2013";
        String sql = "select * from OnlineUser";
 
        try {
        	System.out.println("path:["+System.getProperties().get("java.library.path")+"]");
        	
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url, userName,
                    passwrod);
            Statement stmt = conn.createStatement() ;  
            
            int ret = stmt.executeUpdate("insert into OnlineUser(UserId, DevId, Addr, LastTime, Expires) values('9999','mac','192.168.0.106:888',getdate(),2000)");
            System.out.println("executeUpdate:"+ret);

            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                System.out.println("userId : " + rs.getString(1) + " dev : "
                        + rs.getString(2) + " addr : " + rs.getString("Addr")+ " time : " + rs.getString(4));
            }
 
            // ¹Ø±Õ¼Ç¼¼¯
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
 
            // ¹Ø±ÕÁ´½Ó¶ÔÏó
            if (conn != null) {
                try {
                    conn.close
Ê×Ò³ ÉÏÒ»Ò³ 2 3 4 5 ÏÂÒ»Ò³ βҳ 5/5/5
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºÎªÊ²Ã´²»¼Ç¼Âý²éѯ£¿ ÏÂһƪ£ºwindowsÏÂsqlplus/assysdba±¨ora-..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)