private static String url="jdbc:oracle:thin:@xx.2.xx.47:1522:prodbxxx";
private static String user="xxxxuser";
private static String password="nxxx";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Date date=new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String d=formatter.format(date);
String insert_sql ="INSERT INTO TABLE1 (INTERFACE_KEY,I_OR_U_FLAG,CITY_CODE,CITY_DESC,BUILDING_CODE,BUILDING_DESC,FLOOR_CODE,FLOOR_DESC,ENABLED_FLAG,SUMMARY_FLAG,START_DATE,END_DATE,CREATION_DATE) values ('FA_LOCATION_IMP',NULL,NULL,'"+city+"','"+idc.getBuilding()+"','"+idc.getBuilding()+"','"+idc.getFloor()+"','"+idc.getFloor()+"','Y',NULL,TO_DATE('"+d+"','YYYY-MM-DD'),NULL,SYSDATE)";
Connection conn;
try {
conn = DriverManager.getConnection(url, user, password);
Statement s = conn.createStatement();
s.executeUpdate(insert_sql); // 记住,即使是insert插入语句,也得用executeUpdate方法,而不是execute方法,否则执行失败,返回false,而且还不报错,让你找不到错在哪里。
s.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}