Java数据库处理的方法库DBUtil(2)
发布时间:2021-06-07
发布时间:2021-06-07
3. oracle数据库的select操作,返回select后返回的第一行数据,若要返回int,只需将getString改为getInt
public static String OracleDBSelect(String sql) throws
ClassNotFoundException, SQLException{
String dbURL=”jdbc:oracle:thin:@172.16.4.21:1521:skytest”; String dbuser=”***”;
String dbpasswd=”***”;
Class.forName(”oracle.jdbc.OracleDriver”);
Connection conn = DriverManager.getConnection(dbURL,dbuser,dbpasswd); Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(sql);
rs.next();
int expbalance=rs.getString(1);
rs.close();
stmt.close();
conn.close();
return expbalance;
}
4.oralce数据的执行操作,可执行instert、delete、update等操作,不返回数据
public static void OracleDBUpdate(String sql) throws
ClassNotFoundException, SQLException{
String dbURL=”jdbc:oracle:thin:@172.16.4.21:1521:skytest”; String dbuser=”***”;
String dbpasswd=”***”;
Class.forName(”oracle.jdbc.OracleDriver”);
Connection conn = DriverManager.getConnection(dbURL,dbuser,dbpasswd); Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
5.Cassandra非关系型数据库的操作,包括delete、insert、read等。 public static void CassandraRemove(String USkyid)throws
IllegalStateException, PoolExhaustedException,Exception {
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get(); CassandraClient client = pool.borrowClient(”172.16.4.244″, 9160); try{