17.2 数据库编程试
题
快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题
http://book.51cto.com 2009-08-10 14:13 张昆 电子工业出版社 我要评论(0) 摘要:《Java程序员面试指南》第17章常见的Java上机面试题,本章将经常出现的上机编程题进行分类,希望能够给读者带来帮助和启示。 标签:数据库编程 ava 程序员 Java程序员面试指南 Oracle帮您准确洞察各个物流环节 17.2 数据库编程试题 数据库和常见的开源技术是Java程序员必须掌握的基本技能,面试者一定要熟练掌握相关知识,这样才能在面试中取得满意的成绩。 面试题9 根据
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
结构写出相应的SQL语句 考题题干 有3个表: Employee 职工 (工号,姓名,性别,年龄,部门)(num,name,sex,age,departmentno) Wage工资 (编号,工资金额)(No,amount) Attend出勤 (工号,工资编号,出勤率)(num,No,attendance) 请根据要求,编写相应的SQL语句。 (1)写一个SQL语句,查询工资金额为8000的职工工号和姓名。 (2)写一个SQL语句,查询职工张三的出勤率。 (3)写一个SQL语句,查询3次出勤率为0的职工姓名和工号。 (4)写一个SQL语句,查询出勤率为10并且工资金额小于2500的职工信息。 参考
答案
八年级地理上册填图题岩土工程勘察试题省略号的作用及举例应急救援安全知识车间5s试题及答案
(1)select eml. num,eml.name from Employee eml where (select count(*) from Attend where num =eml.num and No = (select No from Wage where amount ='8000 ')); (2)select amount from Wage where No in (select No from Attend where num=(select num from Employee where name='张三')); (3)select eml.num, eml.name from Employee eml where (select count(*) from Attend where num=eml.num and attendance=0) = 3; (4)select * from Employee eml where (select No from Attend where num=eml.num and attendance='10') = (select No from Wage where amount<2500 ); 面试题10 编写MySQL数据库的JDBC连接 考题题干 请编写访问MySQL数据库的JDBC连接代码,查询数据库中user表的全部内容,并打印出来。 试题分析 读者必须掌握常见的数据库访问内容,包括驱动、端口等参数。 参考答案 具体代码实现如下: 1. import java.sql.Connection; 2. import java.sql.DriverManager; 3. import java.sql.ResultSet; 4. import java.sql.SQLException; 5. import java.sql.Statement; 6. 7. public class DbConn { 8. private static DataSource ds = null; 9. private static Connection conn = null; 10. public static Connection getConn_jdbc() { // 使用JDBC连接数据库 11. try { 12. String url = "jdbc:mysql:// localhost:3306/bbsdb"; 13. String username = "root"; 14. String password = "pla"; 15. Class.forName("com.mysql.jdbc.Driver"). newInstance(); 16. conn = DriverManager.getConnection(url, username, password); 17. return conn; 18. } catch (Exception e) { 19. System.err.println("数据库连接 异常: " + e.getMessage()); 20. return null; 21. } 22. } 23. public void CloseConn() { // 关闭数据库连接 24. try { 25. conn.close(); 26. } catch (Exception e) { 27. System.err.println("数据库连接关 闭异常: " + e.getMessage()); 28. } 29. } 30. public static void main(String[] a) { //测试数据库连接 31. Connection conn; 32. DbConn dc = new DbConn(); 33. conn = dc.getConn_jdbc(); 34. try { 35. Statement stmt = conn.createStatement(); 36. String strSql = "select * from user"; 37. ResultSet rs = stmt.executeQuery(strSql); 38. while (rs.next()) { 39. System.out.println("name:" + rs.getString("name")); 40. } 41. } catch (SQLException e) { 42. e.printStackTrace(); 43. } finally { 44. dc.CloseConn(); // 注意,必 须在最后关闭数据库连接,否则将严重影响系统性能 45. } 46. } 47. }