期終考試題目,國外朋友的,俺不會jsp只好請教大大門
分數好説話
A.JavaBean for retrieving information from a database.
Create a JavaBean (say dbConnector.java) that connects to a database and retrieves and holds information, based on a given SQL query string input.
创建一个基于SQL query string 的输入的JavaBean 用来连接数据库并且检索和储存信息,
a.The bean should have the following functionality 实现如下功能:
i.A function called connect(url, driver, username, password) that takes four String parameters: url, driver, username, password; and then connects to the given database. By default (when the JavaBean is instantiated 对象初始化时), the JavaBean should use the database connection settings specified in the NOTE 1 below 用注释1的值.
ii.A function called executeSQL(sql) that executes “select” type SQL queries. The function takes one String parameter, an SQL query, and it then executes that, and stores the results within a private variable 私有变量 in a 表格格式tabular format (e.g. 2D Array, or Vector of Objects (which Object may be another Vector), or ArrayList of Objects, or anything else that better meets your needs).
iii.A function called updateSQL(sql) that updates, or inserts, or deletes, records from the database. The function takes one String parameter, an SQL query, and it then executes that, and returns the number of records affected by the update.
iv.A function called getHeader(id) which takes one int parameter, the column id, and returns as String the header name at the given column location.
v.A function called getRecord(row, col) which takes two int parameters, the column id, and the row id, and returns as an Object the record at the given cell location.
vi.Other functions that you may find useful; like functions that return the number of columns or number or rows, or functions that clear the local variables (holding record information) in case you want to run a new SQL query.
NOTE 1: There will be (from week 7 onwards) a MySQL database available within the University and each enrolled student will have access to it. To connect to the database use the following settings:
i.URL: "jdbc:mysql://mysql0.ee.surrey.ac.uk:3306/databaseName "
ii.Driver: "org.gjt.mm.mysql.Driver "
iii.Username: Your username
iv.Password: u followed by URN (e.g. u123456)
NOTE 2: To get the ball rolling till you get access to the database and also get familiar with how to retrieve records programmatically, you can just make the JavaBean functions return some hardcoded data (i.e. just fill in the records variable with some data you make up 自己造一些数据去测试它).
[解决办法]
MARK
[解决办法]
不认识英文啊
[解决办法]
看不懂~
[解决办法]
不就是一個很簡單的數據庫操作的封裝嗎
package common.db;
import java.sql.*;
public class Conn {
private static Connection conn;
private Statement stmt;
private ResultSet rs;
private static final String url= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=dboperation; ";
private static final String DriverName= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
public static synchronized Connection getConn() throws Exception{
try{
Class.forName(DriverName);
conn=DriverManager.getConnection(url, "sa ", " ");
return conn;
}catch(SQLException e){
System.err.println(e.getMessage());
throw e;
}
}
public Statement getStmtread(){
try{
conn=getConn();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
return stmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public ResultSet getRs(String sql){
try{
stmt=getStmtread();
rs=stmt.executeQuery(sql);
return rs;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public Statement getStmt(){
try{
conn=getConn();
stmt=conn.createStatement();
return stmt;
}catch (Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public synchronized void close(){
try{
if (rs!=null){
rs.close();
rs=null;
}
}catch (Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
}
try{
if (stmt!=null){
stmt.close();
stmt=null;
}
}catch (Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
}
try{
if (conn!=null){
conn.close();
conn=null;
}
}catch (Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
}
}
}
------解决方案--------------------
How much?If he pay 500$ for it,send mail to me.wow...
[解决办法]
How much?If he pay 450$ for it,send mail to me.wow...