JDBC连接Oracle数据库
时间:2021-07-01 10:21:17
帮助过:18人阅读
public class Test {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1.加载驱动
Class.forName(
"oracle.jdbc.driver.OracleDriver");
//2.获得数据库连接
String url=
"jdbc:oracle:thin:@localhost:1521:orcl";
Connection conn=DriverManager.getConnection(url,
"system",
"toor");
System.out.println(
"连接成功");
//3.执行sql语句
Statement st=
conn.createStatement();
String sql=
"insert into student values(5,‘nama‘,‘man‘)";
st.execute(sql);
System.out.println(
"插入成功");
st.close();
conn.close();
}
}
JDBC连接Oracle数据库
标签:too print str div public 执行 etc import cut