2015-08-20 46 views
-2

我想在我的bean中調用我的數據庫類的方法。 我不知道它爲什麼不工作。 它在技術上是錯誤的? 點擊保存按鈕我想要 1-連接到數據庫 雙插入數據.. 但我有這個錯誤 發生錯誤: 不支持。 +堆棧跟蹤 +組件樹 +作用域變量 我的網頁代碼


我的豆我想創建一個bean中的類的對象,但探險家說不支持?

package DC1; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ManagedProperty; 
import javax.faces.event.ActionEvent; 

@ManagedBean(name = "ctrbean") 
public class ctrbean { 

public ctrbean() { 
} 

private String id ; 
private String pa; 
private String name; 
private String rank; 
private String father ; 
private String dob ; 

public String getId() { 
    return id; 
} 

public void setId(String id) { 
    this.id = id; 
} 

public String getPa() { 
    return pa; 
} 

public void setPa(String pa) { 
    this.pa = pa; 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public String getRank() { 
    return rank; 
} 

public void setRank(String rank) { 
    this.rank = rank; 
} 

public String getFather() { 
    return father; 
} 

public void setFather(String father) { 
    this.father = father; 
} 

public String getDob() { 
    return dob; 
} 

public void setDob(String dob) { 
    this.dob = dob; 
} 

public void insert(ActionEvent ee) 
{ 
avDC1 avd = new avDC1(); 
avd.connect(); 


} 
} 

我的數據庫類

package DC1; 

import java.awt.event.ActionEvent; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.util.List; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.faces.bean.ManagedBean; 
import javax.inject.Scope; 

public class avDC1 { 

public avDC1() { 
} 


private ResultSet rs ; 

public Connection getConnection() { 
    return connection; 
} 

public void setConnection(Connection connection) { 
    this.connection = connection; 
} 

public ResultSet getRs() { 
    return rs; 
} 

public void setRs(ResultSet rs) { 
    this.rs = rs; 
} 



public void connect() 
{ 

try { 

    Class.forName("oracle.jdbc.driver.OracleDriver"); 

} catch (ClassNotFoundException e) { 

    System.out.println("Where is your Oracle JDBC Driver?"); 
    e.printStackTrace(); 
    return; 

} 

try { 

    connection = DriverManager.getConnection(
      "jdbc:oracle:thin:@localhost:1521:XE", "hr", 
      "umair"); 

} catch (SQLException e) { 

    System.out.println("Connection Failed! Check output console"); 
    e.printStackTrace(); 
    return; 

} 

if (connection != null) { 
    System.out.println("You made it, take control your database now!"); 
} else { 
    System.out.println("Failed to make connection!"); 
} 
} 


public void Searchall(ActionEvent ee) 
{ 
try { 
try { 

    Class.forName("oracle.jdbc.driver.OracleDriver"); 

} catch (ClassNotFoundException e) { 

    System.out.println("Where is your Oracle JDBC Driver?"); 
    e.printStackTrace(); 
    return; 

} 

try { 

    connection = DriverManager.getConnection(
      "jdbc:oracle:thin:@localhost:1521:XE", "hr", 
      "umair"); 

} catch (SQLException e) { 

    System.out.println("Connection Failed! Check output console"); 
    e.printStackTrace(); 
    return; 

} 

if (connection != null) { 
    System.out.println("You made it, take control your database now!"); 
} else { 
    System.out.println("Failed to make connection!"); 
} 

String sql = "SELECT * FROM AVIATION" ; 

Statement pdt = connection.createStatement(); 
//  pdt.setString(1,ID); 
//  pdt.setString(2, panumber); 
//  pdt.setString(3,name); 
//  pdt.setString(4, rank); 
//  pdt.setString(5,father); 
//  pdt.setString(6, dob); 

    rs = pdt.executeQuery(sql); 
    rs.next(); 

    String a = rs.getString("NAME"); 
    connection.close(); 

} catch (SQLException ex) { 

Logger.getLogger(avDC1.class.getName()).log(Level.SEVERE, null, ex); 

} 
} //end of search-all 

}//end of class 

這是例外:

java.lang.UnsupportedOperationException: Not supported yet. 
    at DC1.person.<init>(person.java:33) 
    at DC1.NewClass.<init>(NewClass.java:22) 
    at DC1.ctrbean.insert(ctrbean.java:76) 
+0

請發表您的堆棧跟蹤,以便我們能更好地幫助您 – Samuel

+0

java.lang.UnsupportedOperationException:不支持呢。在DC1.person處爲 \t。 (person.java:33) \t at DC1.NewClass。 (NewClass.java:22) \t在DC1.ctrbean.insert(ctrbean.java:76) \t在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) \t在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl。的java:57) \t在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) \t在java.lang.reflect.Method.invoke(Method.java:601) –

+1

實踐多一點與讀取堆棧跟蹤和回溯源代碼中的路徑。而且,源自你自己源的java.lang. *包的異常遠不是Java EE/JSF問題。這只是基本的Java。 – BalusC

回答

0

DC1.person.java線33被明確地拋出UnsupportedOperationException。也許你或你的同事在那裏表明實現不完整。否則,你應該刪除該語句

throw new UnsupportedOperationException("Not supported yet"); 
相關問題