2013年11月1日 星期五

java-template (read MYsql)




import java.sql.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class XMLIR56B {
public static String padL(String s, int n,char t) {
return String.format("%1$" + n + "s", s).replace(' ', t);
}


public static String padR(String s, int n,char t) {
return String.format("%1$-" + n + "s", s).substring(0, n).replace(' ', t);
    }


public static void main( String argv[] ) {
go();
}
public static void go(){
try{
String result="";
ResultSet rs = null;
Connection con = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/hr?useUnicode=true&characterEncoding=UTF8","UseName", "UserPassword");
stmt = con.createStatement();
String sqlString="select recordid from ir56b;";
rs = stmt.executeQuery(sqlString);
while (rs.next()){
System.out.println(rs.getString(1));
}
}catch (Exception e) {
e.printStackTrace();
}
}
}

沒有留言:

張貼留言