package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Insert1 {
public static void main(String[] args) {
Connection conn = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//指定驱动,表示连接到odbc
conn = DriverManager.getConnection("jdbc:odbc:School","scott","tiger");//获取连接,odbc方式情况下,url格式:jdbc:odbc:数据源名称
//2:运行SQL语句:Statement接口
Statement stat = conn.createStatement();
String sql = "INSERT INTO 学籍(学号,姓名,性别,家庭住址) VALUES('222','张三','女','武汉')";
int i = stat.executeUpdate(sql);
System.out.println("添加" + i + "行");
}
catch(Exception ex){
ex.printStackTrace();
}
finally{
try{
if(conn!=null){
conn.close();
conn = null;
}
}catch(Exception ex){}
}
}
}