以下是我在原来基础上对我输出的结果进行的一个格式的规范的转换方法:
使用于"大智慧新一代 2.08.07.0907"日线数据格式转换
以下代码是对某项数据的一个查询的操作代码
使用于"大智慧新一代 2.08.07.0907"日线数据格式转换
public class radaf {
private static ArrayList<Vector<Comparable>> list;
public static void main(String[] args) throws Exception {
list = new ArrayList<Vector<Comparable>>();
DataInputStream in = null;
File f = new File("F:/gupiao.txt");
FileOutputStream fos = new FileOutputStream(f);
PrintWriter pw = new PrintWriter(fos,true);
try
{ // 输入流
in = new DataInputStream(new BufferedInputStream(
new FileInputStream(new File("E:/股票/dzh2/data/sz/day.dat"))));
}
catch (FileNotFoundException fileNotFoundException)
{
fileNotFoundException.printStackTrace();
}
try
{
in.skipBytes(266240);// 跳过前面的数据
Vector vt = new Vector();
DateFormat riqi = new SimpleDateFormat("yyyy-MM-dd");
for(int k=0;k<256;k++){
for (int i = 0; i < 8; i++) {
{
byte[] bt = new byte[4];
in.read(bt);
// 如果是日期的情况
if (i == 0) {
String dateFormat = riqi .format(new Date( 1000 * (long) ((bt[3] & 0xff) << 24 | (bt[2] & 0xff) << 16 | (bt[1] & 0xff) << 8 | (bt[0] & 0xff)))).toString();
vt.add(dateFormat);
//out.StringWriter(dateFormat,0,dateFormat.length());
System.out.println("日期: " + dateFormat);
//pw.write("\n\r");
pw.write("\r\n"+dateFormat);
pw.flush();
}
else{
Float dateFloat = new Float(Float .intBitsToFloat((bt[3] & 0xff) << 24 | (bt[2] & 0xff) << 16 | (bt[1] & 0xff) << 8 | (bt[0] & 0xff)));
vt.add(dateFloat);
System.out.println(dateFloat);
pw.print(" "+dateFloat);
pw.flush();
//out.writer(dateFloat,0,dateFloat.length());
}
} pw.write("\n");
list.add(vt);
}
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if (in != null)
in.close();
if (pw != null)
{
pw.close();
}
}
}
}
以下代码是对某项数据的一个查询的操作代码
import java.sql.*;
public class JDBCTest {
public static void main(String[] args){
// 驱动程序名
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://localhost:3306/test";
// MySQL配置时的用户名
String user = "chenlong";
// MySQL配置时的密码
String password = "123456";
try {
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from gubiao";
// 结果集
ResultSet rs = statement.executeQuery(sql);
System.out.println("执行结果如下所示:");
//System.out.println("日期" + "\t" + " 成交金额");
//System.out.println("-----------------");
//String name = null;
// String money =null;
// 输出结果
while(rs.next()) {
// 选择sname这列数据
// name = rs.getString("sname");
// 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
// 然后使用GB2312字符集解码指定的字节数组
// name = new String(name.getBytes("ISO-8859-1"),"GB2312");
// 输出结果
//System.out.println(rs.getString("sno") + "\t" + name);
System.out.println(rs.getString("date") );
System.out.println(rs.getString("menoy") );
}
rs.close();
conn.close();
} catch(ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}