JDBC的学习
来源:互联网 发布:淘宝咖啡猫游戏代购 编辑:程序博客网 时间:2024/06/03 21:50
package com.company;import java.sql.*;public class Main { //public static void Insertdept(int deptno, String dname, String loc)throws ClassNotFoundException, SQLException public static void Updatedept(String loc,int deptno)throws ClassNotFoundException, SQLException {// Class.forName("oracle.jdbc.driver.OracleDriver");// String strUrl="jdbc:oracle:thin:@localhost:1521:orcl";// Connection con=DriverManager.getConnection(strUrl,"scott","lwz315");// Statement st= con.createStatement();// String strSql="insert into dept values("+deptno+",'"+dname+"','"+loc+"')";// st.executeUpdate(strSql);// st.close();// con.close(); Class.forName("oracle.jdbc.driver.OracleDriver"); String strUrl="jdbc:oracle:thin:@localhost:1521:orcl"; Connection con=DriverManager.getConnection(strUrl,"scott","lwz315"); Statement st= con.createStatement(); String strSql="UPDATE dept set loc='"+loc+"' where deptno="+deptno; st.executeUpdate(strSql); st.close(); con.close(); } public static void main(String[] args) throws SQLException, ClassNotFoundException {//// write your code here// //1.加载jdbc驱动// Class.forName("com.mysql.jdbc.Driver");// //2.定义连接url// String strUrl ="jdbc:mysql://localhost:3306/scott";// //3.获取数据库连接// Connection con= DriverManager.getConnection(strUrl,"root","root");// //4.获得statement对象(用来执行sql语句,并返回结果)// Statement st=con.createStatement();// //5.执行查询或更新// String strSql="select * from emp";// //6.处理结果(遍历获取出来的所有数据)// ResultSet rs = st.executeQuery(strSql);//// while (rs.next())// {// int nEmpNo=rs.getInt("empno");// String strName=rs.getString("ename");// String strJob=rs.getString("job");// Date d=rs.getDate("hiredate");// System.out.println(nEmpNo+" "+strName+" "+d+" "+strJob);// }// //7.关闭连接(释放资源)// rs.close();// st.close();// con.close(); // --------------------// Class.forName("oracle.jdbc.driver.OracleDriver");// String strUrl="jdbc:oracle:thin:@localhost:1521:orcl";// Connection con=DriverManager.getConnection(strUrl,"scott","lwz315");// Statement st= con.createStatement();// String strSql="select * from emp";// ResultSet rs=st.executeQuery(strSql);// while (rs.next())// {// int nEmpNo=rs.getInt("empno");// String strName=rs.getString("ename");// String strJob=rs.getString("job");// System.out.println(nEmpNo+" "+strName+" "+strJob);// }// rs.close();// st.close();// con.close(); //Insertdept(90,"技术部","沈阳"); Updatedept("铁岭",90); }}
0 0
- 简单的学习JDBC
- JDBC的学习总结
- Java的JDBC学习
- 关于jdbc的学习
- JDBC的学习记录
- JDBC的学习
- JDBC的学习
- JDBC的再学习
- jdbc的学习
- JDBC的学习
- 学习JDBC的总结
- JDBC的学习 一
- 学习jdbc的总结
- 牛人写的 JDBC学习-总结- -
- Jdbc的学习,全面总结
- SUN的JDBC学习中心
- JDBC的MYSQL继续学习
- Android之jdbc的学习
- MySQL数据库备份与还原
- angularJs 解决跨域访问问题
- JavaBean 实现Mysql数据库操作(Query、Insert、Delete、Update)
- 19. Remove Nth Node From End of List (移除链表倒数第n个节点)
- Scintilla笔记(2)
- JDBC的学习
- OpenCV人脸检测(C++代码)—— By wepon
- POJ-1273 Drainage Ditches(最大流)
- Android 对话框弹出底部背景透明度调节
- java xml解析
- Scintilla笔记(3)
- request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- 备忘录模式(Memento Pattern)
- ubuntu 终端命令