•
String className="oracle.jdbc.driver.OracleDriver";
•
String url="jdbc:oracle:thin:@localhost:1521:orcl";
•
String username="supermarket";
•
String userpass="abc";
•
Connection con=null;
•
PreparedStatement pstmt=null;
•
ResultSet rs=null;
•
public String ss="";
•
public boolean existname(String ID){
•
try{
•
Class.forName(className);
•
con=DriverManager.getConnection(url,username,userpass);
•
pstmt=con.prepareStatement("select * from Provide where
ProvideID='"+ID+"'");
•
rs=pstmt.executeQuery();
•
while(rs.next()){
•
for(int i=0;i<rs.getMetaData().getColumnCount();i++){
•
ss=ss+rs.getString(i+1).toString();
•
}
•
}
•
}catch(Exception e){
•
System.out.println(e.toString());
•
}finally{
•
try{rs.close();}catch(Exception ee){};
•
try{pstmt.close();}catch(Exception ee){};
•
try{con.close();}catch(Exception ee){};
•
}
返回目录
连接数据库注意要设置:
工程 - 右键( build path ) -confi
gure build path--add external---E:
\oracle\product\10.2.0\db_1\jdbc\
lib\class12.jar