try {
Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
con = DriverManager.getConnection(jdbc
racle:thin
YouDbhost:1521:YouDatabase,
YouDbUser, YouDbPasswd);
result = true ;
} catch (ClassNotFoundException cnfe) {
System.out.println("Not Found Oracle Driver");
method.error("Not Found Oracle Driver") ;
} catch (Exception e) {
System.out.println("connect Oracle has error");
method.error("connect Oracle has error") ;
}
PreparedStatement pstmt=null;
ResultSet rs = null;
String sqlreturn;
String sQuery ="select YouStrField from testtable";
pstmt = con.prepareStatement(sQuery) ;
rs = pstmt.executeQuery() ;
if (rs.next()){
sqlreturn=rs.getString(1)
}
pstmt.close() ;
上面这个例子主要是针对ORACLE的
你可以参考一下