tempad
ReadyGo!技术成就梦想 >>数据库 >> 讲解jython访问MySQL数据库的具体步骤

讲解jython访问MySQL数据库的具体步骤

ReadyGo!技术成就梦想 网络搜索 efish 2008-8-2 17:10:38

【-IT技术报道】

准备工作如下:

下载

http://jaist.dl.sourceforge.net/sourceforge/zxjdbc/zxJDBC-2.1.tar.gz

http://jaist.dl.sourceforge.net/sourceforge/jython/jython_installer-2.2.1.jar

http://mmmysql.sourceforge.net/dist/mm.mysql-2.0.4-bin.jar

安装(需要已经安装了jdk/jre?)

java -jar jython_installer-2.2.1.jar 安装到C:\jython2.2.1

将zxJDBC.jar解压缩到c:\tmp

将mm.mysql-2.0.4-bin.jar复制到c:\tmp

C:\jython2.2.1>set CLASSPATH=c:\tmp\mm.mysql-2.0.4-bin.jar;c:\tmp\zxJDBC.jar;%CLASSPATH%

启动mysql服务器 C:\mysql51>cd bin C:\mysql51\bin>mysqld --console 并建立数据库 C:\mysql51\bin>mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.14-beta-community MySQL Community Server (GPL) Type "help;" or "\h" for help. Type "\c" to clear the buffer. mysql> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+ 2 rows in set (0.00 sec) mysql> create database test; Query OK, 1 row affected (0.01 sec) mysql> use test Database changed mysql> create table a1(c1 varchar(30)); Query OK, 0 rows affected (0.02 sec) mysql> insert into a1 values ("Hello World"); Query OK, 1 row affected (0.00 sec) 进入jython环境访问mysql C:\jython2.2.1>jython Jython 2.2.1 on java1.6.0 Type "copyright", "credits" or "license" for more information. >>> from com.ziclix.python.sql import zxJDBC >>> mysqlConn = zxJDBC.connect("jdbc:mysql://localhost/test", ... "root", "", ... "org.gjt.mm.mysql.Driver") >>> cursor = mysqlConn.cursor() >>> cursor.execute("SELECT * FROM a1"); >>> cursor.fetchone() ("Hello World",) >>> cursor.fetchall() >>>

需要用jython自己封装的dbexts库

最后编辑一个名为dbexts.ini的文件保存到c:\jython2.2.1\lib

name=mysqltest name=mysqltest url=jdbc:mysql://localhost/test user=root pwd= driver=org.gjt.mm.mysql.Driver 进入jython >>> from dbexts import dbexts >>> mysqlcon = dbexts("mysqltest", "c:\jython2.2.1\lib\dbexts.ini >>> mysqlcon.table() TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS ----------------------------------------------------------- | | a1 | TABLE | 1 row affected >>> mysqlcon.table("a1") TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | S | NUM_PREC_RADIX | NULLABLE | REMARKS | COLUMN_DEF | SQL_DATA_ SITION | IS_NULLABLE ---------------------------------------------------------------- ---------------------------------------------------------------- -------------------- | | a1 | c1 | 12 | | 10 | 1 | | | 0 | YES 1 row affected >>> mysqlcon.isql("SELECT * FROM a1") C1 ----------- Hello World 1 row affected DML >>> mysqlcon.isql("insert into a1 values("insert by dbexts")") >>> mysqlcon.isql("SELECT * FROM a1") C1 ---------------- Hello World insert by dbexts 2 rows affected

(责任编辑:卢兆林)

责任编辑: efish 参与评论 查找更多:
相关文章
MySQL数据库中如何解决分组统计的问题 MySQL数据库中如何解决分组统计的问题
SAVEPOINT和ROLLBACK TO SAVEPOINT语法 SAVEPOINT和ROLLBACK TO SAVEPOINT语法
MySQL的存储过程写法和"Cursor"的使用 MySQL的存储过程写法和"Cursor"的使用
深入讲解"InnoDB"和"MyISAM"的不同之处 深入讲解"InnoDB"和"MyISAM"的不同之处
实例讲解"MySQL"在记录不存在时的插入 实例讲解"MySQL"在记录不存在时的插入
带你轻松接触一个检测MySQL状态的脚本 带你轻松接触一个检测MySQL状态的脚本
如何安装配置基于2台服务器的MySQL集群 (1) 如何安装配置基于2台服务器的MySQL集群 (1)
深入剖析MySQL数据库字符集的出错现象 深入剖析MySQL数据库字符集的出错现象
MySQL:使用源码分发版还是二进制分发版 MySQL:使用源码分发版还是二进制分发版
通过数据仓库来实现少花钱多办事的目的 通过数据仓库来实现少花钱多办事的目的
2秒记住本站域名

玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn

分类导航
ReadyGo!技术成就梦想