http://documents.wolfram.com/mathematica/Add-onsLinks/DatabaseLink/
Needs["DatabaseLink`"]
DatabaseExplorer[]
1.如何把数据库的JDBC的驱动加入?
把JDBC的jar文件复制到Mathematica DataBaseResource 属性location 指定的目录下。如图
2.这样就可以建立了DatabaseResource资源了,然后就可以在notebook程序中使用了。
使用语法,如果熟悉ODBC或JDBC就非常容易理解了。
Needs["DatabaseLink`"]
(*DatabaseExplorer[]*)
conn= OpenSQLConnection[JDBC["org.gjt.mm.mysql.Driver", "jdbc:mysql://10.2.5.240:3306/HK_PCD55"], "Name" -> "test",
"Description" -> "", "Username" -> "root", "Password" -> "",
"RelativePath" -> False, "Version" -> 1]
(*建立连接,也可以通过配置文件的方式来设置,可参看具体的http://documents.wolfram.com/mathematica/Add-onsLinks/DatabaseLink/DatabaseConnections/EstablishingAConnection/DatabaseLink2.2.1.html*)
SQLSelect[conn,"att_L_LeaveType"]
SQLExecute[conn,"select * from att_L_LeaveType"]
CloseSQLConnection[conn]
可以通过:JDBCDriverNames[] 来得到当前Mathematica内所有的配置数据库
得到某个具体的数据源的具体配置通过命令: JDBCDrivers["mysql"]
星期三, 七月 26, 2006
星期一, 七月 17, 2006
如何用HTML来显示对应UTF-8的汉字?
HTML默认支持Unicode的方式是UTF-8编码。
所以任何Unicode字符集的 字体要用HTML表示出来,必须得到对应的UTF-8编码。
比如符号:? 对应的Unicode的字符集合编码为:A87C.
但是对应的UTF-8的编码就为:8525(十六进制)
所以用HTML来表示就为 ▅
显示出来:?
注意:要根据原来UNICODE字符集合的高低位顺序确定HTML的字节表示方法。
UTF-8根据:低位->高位来表示字符顺序
Encoding Representation
UTF-8 EF BB BF
UTF-16 Big Endian FE FF
UTF-16 Little Endian FF FE
UTF-32 Big Endian 00 00 FE FF
UTF-32 Little Endian FF FE 00 00
所以任何Unicode字符集的 字体要用HTML表示出来,必须得到对应的UTF-8编码。
比如符号:? 对应的Unicode的字符集合编码为:A87C.
但是对应的UTF-8的编码就为:8525(十六进制)
所以用HTML来表示就为 ▅
显示出来:?
注意:要根据原来UNICODE字符集合的高低位顺序确定HTML的字节表示方法。
UTF-8根据:低位->高位来表示字符顺序
Encoding Representation
UTF-8 EF BB BF
UTF-16 Big Endian FE FF
UTF-16 Little Endian FF FE
UTF-32 Big Endian 00 00 FE FF
UTF-32 Little Endian FF FE 00 00
星期日, 七月 09, 2006
Mathematica 5.0 All 关键词的妙用
lotterydata={
{12,13,17,19,29,30,32,2006001},
{02,13,14,23,32,34,35,2006002},
{03,08,09,13,29,31,35,2006003},
{06,09,16,23,31,33,34,2006004},
{11,12,21,23,26,30,34,2006005},
{06,07,09,18,20,22,28,2006006},
{01,04,05,07,09,17,24,2006007},
{03,17,18,20,22,31,35,2006008},
{04,05,07,15,17,19,28,2006009},
{02,06,15,20,26,32,35,2006010},
{02,04,06,11,23,24,32,2006011},
{04,06,09,13,24,31,35,2006012},
{05,06,07,22,25,26,30,2006013},
{07,17,18,19,23,28,32,2006014},
{04,09,17,19,22,24,35,2006015},
{13,16,20,23,25,26,33,2006016},
{01,02,06,10,12,19,25,2006017},
{01,02,06,15,16,31,34,2006018},
{15,17,22,23,24,33,35,2006019}}
lotterydata[[All,3]](*取出每一纬第3个数据*)
得到结果:{17,14,9,16,21,9,5,18,7,15,6,9,7,18,17,20,6,6,22}
{12,13,17,19,29,30,32,2006001},
{02,13,14,23,32,34,35,2006002},
{03,08,09,13,29,31,35,2006003},
{06,09,16,23,31,33,34,2006004},
{11,12,21,23,26,30,34,2006005},
{06,07,09,18,20,22,28,2006006},
{01,04,05,07,09,17,24,2006007},
{03,17,18,20,22,31,35,2006008},
{04,05,07,15,17,19,28,2006009},
{02,06,15,20,26,32,35,2006010},
{02,04,06,11,23,24,32,2006011},
{04,06,09,13,24,31,35,2006012},
{05,06,07,22,25,26,30,2006013},
{07,17,18,19,23,28,32,2006014},
{04,09,17,19,22,24,35,2006015},
{13,16,20,23,25,26,33,2006016},
{01,02,06,10,12,19,25,2006017},
{01,02,06,15,16,31,34,2006018},
{15,17,22,23,24,33,35,2006019}}
lotterydata[[All,3]](*取出每一纬第3个数据*)
得到结果:{17,14,9,16,21,9,5,18,7,15,6,9,7,18,17,20,6,6,22}
星期五, 七月 07, 2006
Java Headless 测试代码for jdk >1.3
import java.awt.*;
import java.io.*;
import java.awt.print.*;
import javax.imageio.*;
import java.io.*;
import java.util.logging.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Color;
import java.awt.Font;
import javax.imageio.ImageIO;
import java.awt.font.*;
import java.awt.geom.*;
import javax.naming.*;
public class HeadlessBasics
{
public static void main(String[] args) throws Exception
{
// Set system property.
// Call this BEFORE the toolkit has been initialized, that is,
// before Toolkit.getDefaultToolkit() has been called.
System.setProperty("java.awt.headless", "true");
// This triggers creation of the toolkit.
// Because java.awt.headless property is set to true, this
// will be an instance of headless toolkit.
Toolkit tk = Toolkit.getDefaultToolkit();
// Standard beep is available.
tk.beep();
// Check whether the application is
// running in headless mode.
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println("Headless mode: " + ge.isHeadless());
HeadlessBasics hb=new HeadlessBasics();
ImageIO.write(hb.DisplayTextPicture("dddd") , "png", new File("first"));
}
public BufferedImage DisplayTextPicture(String willtext)
{
int width = 48;
int height = 48;
float size = 8.0f;
int StringH = 8;
BufferedImage buffer = new BufferedImage(width,
height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 =(Graphics2D)buffer.getGraphics();
Font font = new Font("serif", Font.BOLD, StringH);
font = font.deriveFont(size);
FontRenderContext fc = g2.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(willtext,
fc);
width = (int) bounds.getWidth();
height = (int) bounds.getHeight() * 2;
buffer = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
g2 = (Graphics2D)buffer.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setFont(font);
g2.setColor(Color.white);
g2.fillRect(0, 0, width, height);
g2.setColor(Color.red);
String[] tem = willtext.split("\n");
for (int i = 0; i < tem.length; i++)
g2.drawString(tem[i], 0,
(int) - bounds.getY() + i * StringH);
return buffer;
}
}
import java.io.*;
import java.awt.print.*;
import javax.imageio.*;
import java.io.*;
import java.util.logging.*;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Color;
import java.awt.Font;
import javax.imageio.ImageIO;
import java.awt.font.*;
import java.awt.geom.*;
import javax.naming.*;
public class HeadlessBasics
{
public static void main(String[] args) throws Exception
{
// Set system property.
// Call this BEFORE the toolkit has been initialized, that is,
// before Toolkit.getDefaultToolkit() has been called.
System.setProperty("java.awt.headless", "true");
// This triggers creation of the toolkit.
// Because java.awt.headless property is set to true, this
// will be an instance of headless toolkit.
Toolkit tk = Toolkit.getDefaultToolkit();
// Standard beep is available.
tk.beep();
// Check whether the application is
// running in headless mode.
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println("Headless mode: " + ge.isHeadless());
HeadlessBasics hb=new HeadlessBasics();
ImageIO.write(hb.DisplayTextPicture("dddd") , "png", new File("first"));
}
public BufferedImage DisplayTextPicture(String willtext)
{
int width = 48;
int height = 48;
float size = 8.0f;
int StringH = 8;
BufferedImage buffer = new BufferedImage(width,
height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 =(Graphics2D)buffer.getGraphics();
Font font = new Font("serif", Font.BOLD, StringH);
font = font.deriveFont(size);
FontRenderContext fc = g2.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(willtext,
fc);
width = (int) bounds.getWidth();
height = (int) bounds.getHeight() * 2;
buffer = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
g2 = (Graphics2D)buffer.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setFont(font);
g2.setColor(Color.white);
g2.fillRect(0, 0, width, height);
g2.setColor(Color.red);
String[] tem = willtext.split("\n");
for (int i = 0; i < tem.length; i++)
g2.drawString(tem[i], 0,
(int) - bounds.getY() + i * StringH);
return buffer;
}
}
订阅:
博文 (Atom)