日期:2014-05-20 浏览次数:20854 次
import java.sql.*; public class JDBCDemo { public JDBCDemo() { } public static void main(String[] args){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:MyODBC","sa",""); String str = ("insert into job(id,name,age,sex) values(1,'张三',18,'男')"); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(str); conn.close(); }catch(ClassNotFoundException cnfe){ cnfe.printStackTrace(); }catch(SQLException sqle){ sqle.printStackTrace(); } } }
int nunber = stm.executeUpdate(str); if(number==1){ // 成功插入数据 }