易截截图软件、单文件、免安装、纯绿色、仅160KB

JAVA常用操作语句 项目中的总结六


判断一个文件是否为二进制文件
public static boolean isBinary(File file) {
boolean isBinary = false;
try {
FileInputStream fin = new FileInputStream(file);
long len = file.length();
  for (int j = 0; j < (int) len; j++) {
int t = fin.read();
if (t < 32 && t != 9 && t != 10 && t != 13) {
isBinary = true;
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return isBinary;
}
将一个student.txt文件的数据导入MySQL数据库中一张student1表中:
import java.io.*;
import java.sql.*;
import java.util.*;
public class TextToDataBase {
/**
* @param args
* 本程序涉及文件IO,字符串分隔StringTokenizer,JDBC,数据库sql语句
*/
public static void main(String[] args) {
Connection con=null;
PreparedStatement pstm=null;

FileReader fr=null;
BufferedReader br=null;
try {

Class.forName("com.mysql.jdbc.Driver");

con=DriverManager.getConnection("jdbc:mysql://localhost:3306/exercise1","root","root");

pstm=con.prepareStatement("insert into student1 (ID,name,age,gendar,score) values(?,?,?,?,?)");


fr=new FileReader("D:\\Exercise\\student.txt");
br=new BufferedReader(fr);

for(int i=0;i<5;i++){

String s=br.readLine();
StringTokenizer st=new StringTokenizer(s);
 
int ID=Integer.parseInt(st.nextToken());
String name=st.nextToken();
int age=Integer.parseInt(st.nextToken());
String gendar=st.nextToken();
int score=Integer.parseInt(st.nextToken());
 
pstm.setInt(1,ID);
pstm.setString(2,name);
pstm.setInt(3,age);
pstm.setString(4,gendar);
pstm.setInt(5,score);
pstm.executeUpdate();
}
br.close();
pstm.close();
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();


相关文档:

Java JDK 版本的区别

jdk6和jdk5相比的新特性有:
1、instrumentation
在 Java SE 6 里面,instrumentation 包被赋予了更强大的功能:启动后的 instrument、本地代码 instrument,以及动态改变 classpath 等等。
2、Http有所增强
3、 Java 管理扩展(JMX) 架构及其框架,以及在 Java SE 5 中新引入的 JMX API -- java.l ......

关于java打包

一个简单的双击就能运行jar文件的打包过程:
http://blog.csdn.net/ihc523/archive/2009/10/11/4636832.aspx
eclipse导出jar文件再将它转换成exe可执行文件:
http://hi.baidu.com/%C4%CF%BA%BD%CC%EC%CF%C2/blog/item/1601a381ac9af9d1bd3e1e3d.html
打Jar包的一个Eclipse插件FatJar:
http://blog.csdn.net/lqsmn613/ar ......

java script 获得Label控件内容

 var ProjectName = document.getElementById("<%=ProjectName.ClientID%>").innerText;
       ProjectName = ProjectName.replace(/(^\s*)|(\s*$)/g, ""); // 相当于Trim()函数 ......

Java中的byte


最近因为在做金融项目,里面对byte的操作要求比较多,所以在这里整理了一下关于Java中的byte类型。
Java虚拟机中没有byte类型
恩。。。怎么说呢,个人感觉这个说法有点儿唬人的意思。的确,当这个想法刚刚出现在我的脑海中的时候我觉得也有些胡扯,毕竟byte类型就在那里,怎么能说Java虚拟机中没有byte类型呢?
好吧, ......

JAVA常用操作语句 项目中的总结五


数字的格式化
DecimalFormat df = new DecimalFormat(",###.00");  
double aNumber = 33665448856.6568975; 
String result = df.format(aNumber);  
Sytem. out.println(result);

输出结果为:
33,665,448,856.66 
分析字符串 
StringTokenizer(String s) 构造一 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号