-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOID_Sample.java
More file actions
100 lines (83 loc) · 2.6 KB
/
Copy pathOID_Sample.java
File metadata and controls
100 lines (83 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.sql.*;
import cubrid.sql.*; //a
import cubrid.jdbc.driver.*;
import java.lang.*;
class OID_Sample
{
public static void main (String args [])
{
// Making a connection
String url= "jdbc:cubrid:192.168.2.107:30000:api04db:public::";
String user = "dba";
String passwd = "";
// SQL statement to get OID values
String sql = "SELECT class_of from _db_class where class_name='api04a' ";
// Declaring variables for Connection and Statement
Connection con = null;
Statement stmt = null;
CUBRIDResultSet rs = null;
ResultSetMetaData rsmd = null;
PreparedStatement preStmt = null;
Object classobj = null;
try {
Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unable to load Cubrid driver", e);
}
try {
con = DriverManager.getConnection(url, user, passwd);
stmt = con.createStatement();
rs = (CUBRIDResultSet)stmt.executeQuery(sql);
rsmd = rs.getMetaData();
CUBRIDResultSet rsoid =null;
rs.next();
CUBRIDOID oid = rs.getOID(1);
System.out.println (oid2bytes (oid.getOID()));
classobj = rs.getObject(1); //d
con.commit(); //g
} catch(CUBRIDException e) {
e.printStackTrace();
} catch(SQLException ex) {
ex.printStackTrace();
} finally {
if(rs != null) try { rs.close(); } catch(SQLException e) {}
if(stmt != null) try { stmt.close(); } catch(SQLException e) {}
if(con != null) try { con.close(); } catch(SQLException e) {}
}
}
static public long oid2bytes(byte[] oid){
int page_data = 0;
short slot_data = 0;
short volume_data = 0;
long ret = 0;
long tmp = 0;
/*OID : (volid | pageid | slotid) */
int startIndex = 0;
int endIndex = 4;
/*page ID*/
if(oid == null) return -1;
for(int i = startIndex; i< endIndex; i++){
page_data <<= 8;
page_data |= (oid[i] & 0xff);
}
startIndex = 4;
endIndex = startIndex + 2;
for(int i = startIndex; i < endIndex; i++){
slot_data <<= 8;
slot_data |= (oid[i] & 0xff);
}
startIndex = 6;
endIndex = startIndex + 2;
for(int i = startIndex; i < endIndex; i++){
volume_data <<=8;
volume_data |= (oid[i] & 0xff);
}
ret <<=16;
ret |= volume_data & 0xffff;
ret <<=16;
ret |= slot_data & 0xffff;
ret <<=32;
ret |= page_data & 0xffffffff;
return ret;
}
}