how to Convert X and Y to lat and long - java

I have a table called IK_TEMP and it contains columns called data, range .
String sql = "SELECT DATA, RANGE FROM IK_TEMP";
try (Connection conn = this.connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)){
// loop through the result set
while (rs.next()) {
System.out.println(rs.getString("DATA") + "\t" +
rs.getBytes("RANGE"));
fromBytes(rs.getBytes("RANGE"));
}
The RANGE field(binary / BLOB) field is already encoded using binary from arcGIS and saved in the Database.
http://www.geopackage.org/spec120/#gpb_format
I want to decode this RANGE field using java.
Here I have tried with fromBytes method
public void fromBytes(byte[] bytes) {
this.bytes = bytes;
ByteReader reader = new ByteReader(bytes);
// Get 2 bytes as the magic number and validate
String magic = null;
try {
magic = reader.readString(2);
} catch (UnsupportedEncodingException e) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry magic number character encoding: Expected: "
+ GeoPackageConstants.GEOMETRY_MAGIC_NUMBER);
}
if (!magic
.equals(GeoPackageConstants.GEOMETRY_MAGIC_NUMBER)) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry magic number: "
+ magic
+ ", Expected: "
+ GeoPackageConstants.GEOMETRY_MAGIC_NUMBER);
}
// Get a byte as the version and validate, value of 0 = version 1
byte version = reader.readByte();
if (version != GeoPackageConstants.GEOMETRY_VERSION_1) {
throw new GeoPackageException(
"Unexpected GeoPackage Geometry version: "
+ version
+ ", Expected: "
+ GeoPackageConstants.GEOMETRY_VERSION_1);
}
// Get a flags byte and then read the flag values
byte flags = reader.readByte();
int envelopeIndicator = readFlags(flags);
reader.setByteOrder(byteOrder);
// Read the 5th - 8th bytes as the srs id
srsId = reader.readInt();
// Read the envelope
envelope = readEnvelope(envelopeIndicator, reader);
// Save off where the WKB bytes start
wkbGeometryIndex = reader.getNextByte();
// Read the Well-Known Binary Geometry if not marked as empty
if (!empty) {
geometry = GeometryReader.readGeometry(reader);
}
}
I am getting x and y coordinates and geometryType in geometry object, But how can I get lat and long from this
In one of the example they have given in JS reff.
for item in (GeometryDataXYValue)!{
let xValue = item.paths?.ofX
let yValue = item.paths?.ofY
//recieve x y point
currentPoint = AGSPoint(x: xValue!, y: yValue!, spatialReference: AGSSpatialReference.webMercator())
//convert to lat long by AGSSpatialReference.wgs84()
if let aReference = AGSGeometryEngine.projectGeometry(currentPoint!, to: AGSSpatialReference.wgs84()) as? AGSPoint {
currentPoint = aReference
}
}
var long:Double = currentPoint!.x
var lat: Double = currentPoint!.y
print("value long lat = \(long , lat)")
}
But I want the same conversion in java.
This is another example
example

Please try the following methods to obtain data:
Blob picture = resultSet.getBlob("RANGE");
inputStream = picture.getBinaryStream();
outputStream = new FileOutputStream("D:\\blob\\RANGE.jpg");
byte[] bufferBytes = new byte[1024];
int len = 0;
while ((len = inputStream.read(bufferBytes)) != -1) {
outputStream.write(bufferBytes, 0, len);
}

You can get the lat and long by using the geotools library.
Coordinate coordinate = new Coordinate(geometry.getEnvelope().getMaxX(), geometry.getEnvelope().getMaxY());
MathTransform transform;
Coordinate targetGeometry;
double latitude;
double longitude;
try {
//sourceCRS is to convert the X and Y coordinates to lat long
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:25832");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
targetGeometry = JTS.transform(coordinate, coordinate, transform);
latitude = targetGeometry.getX();
longitude = targetGeometry.getY();
} catch (FactoryException | TransformException e) {
e.printStackTrace();
}
}

Related

How to Verify Mobile no and email id from Secure QR code of Aadhaar card

Official Document for How to Read QR code data from Secure QR code of UIDAI Aadhaar card: https://uidai.gov.in/images/resource/User_manulal_QR_Code_15032019.pdf
Have used zxing scanner to scan Secure QR code,
And was able to get details of aadhar card with the help of follow project in Github:
https://github.com/dimagi/AadharUID
Some how I figured out how to extract photo and bit_indicator_value from converted byte array with the help of instructions on document
But I am unable to get hashed exact hashed value of email and mobile from Secure QR code of Aadhar card byte array to verify
I am bit confused from this line of above mentioned document in page no 6:
Post getting signature value, check the value of
Email_mobile_present_bit_indicator_value:
if its 3 then first read mobile from index (Byte array length – 1-256) and then email from index (Byte array length – 1- 256- 32) in
reverse order. Each value will be of fix size of 32 byte.
If Email_mobile_present_bit_indicator_value is 1 then only mobile
is present.
If Email_mobile_present_bit_indicator_value is 2 then only email is
present.
If Email_mobile_present_bit_indicator_value is 0 then no mobile or
email present.
Email and Mobile value will available in byte. Convert into Hexadecimal
String.
.
I have also prepared last step in document page no 6 but the users mobile/email hash value and documents mobile/email byte arrays hash value never matches
Code snippet:
public ScanResult(String input) {
rawString = input;
// copied from http://www.java-samples.com/showtutorial.php?tutorialid=152
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document dom;
try {
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Replace </?xml... with <?xml...
if (input.startsWith("</?")) {
input = input.replaceFirst("</\\?", "<?");
}
// Replace <?xml...?"> with <?xml..."?>
input = input.replaceFirst("^<\\?xml ([^>]+)\\?\">", "<?xml $1\"?>");
//parse using builder to get DOM representation of the XML file
dom = db.parse(new ByteArrayInputStream(input.getBytes("UTF-8")));
} catch (ParserConfigurationException | SAXException | IOException e) {
dom = null;
}
if (rawString.matches("[0-9]*")) {
type = QR_CODE_TYPE_SECURE;
byte[] msgInBytes = null;
try {
msgInBytes = decompressByteArray(new BigInteger(rawString).toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
if (msgInBytes != null) {
int[] delimiters = locateDelimiters(msgInBytes);
String referenceId = getValueInRange(msgInBytes, delimiters[0] + 1, delimiters[1]);
uid = referenceId.substring(0, 4);
name = getValueInRange(msgInBytes, delimiters[1] + 1, delimiters[2]);
dob = formatDate(getValueInRange(msgInBytes, delimiters[2] + 1, delimiters[3]),
new String[] {"dd-MM-yyyy", "dd/MM/yyyy"});
yob = dob.substring(0, 4);
gender = getValueInRange(msgInBytes, delimiters[3] + 1, delimiters[4]);
co = getValueInRange(msgInBytes, delimiters[4] + 1, delimiters[5]);
dist = getValueInRange(msgInBytes, delimiters[5] + 1, delimiters[6]);
lm = getValueInRange(msgInBytes, delimiters[6] + 1, delimiters[7]);
house = getValueInRange(msgInBytes, delimiters[7] + 1, delimiters[8]);
loc = getValueInRange(msgInBytes, delimiters[8] + 1, delimiters[9]);
pc = getValueInRange(msgInBytes, delimiters[9] + 1, delimiters[10]);
po = getValueInRange(msgInBytes, delimiters[10] + 1, delimiters[11]);
state = getValueInRange(msgInBytes, delimiters[11] + 1, delimiters[12]);
street = getValueInRange(msgInBytes, delimiters[12] + 1, delimiters[13]);
subdist = getValueInRange(msgInBytes, delimiters[13] + 1, delimiters[14]);
vtc = getValueInRange(msgInBytes, delimiters[14] + 1, delimiters[15]);
statusCode = STATUS_SUCCESS;
} else {
statusCode = STATUS_PARSE_ERROR;
uid = "";
name = "";
gender = "";
yob = "";
co = "";
house = "";
street = "";
lm = "";
loc = "";
vtc = "";
po = "";
dist = "";
subdist = "";
state = "";
pc = "";
dob = "";
}
} else {
type = QR_CODE_TYPE_UNKNOWN;
statusCode = STATUS_PARSE_ERROR;
uid = "";
name = "";
gender = "";
yob = "";
co = "";
house = "";
street = "";
lm = "";
loc = "";
vtc = "";
po = "";
dist = "";
subdist = "";
state = "";
pc = "";
dob = "";
}
dobGuess = getDobGuess(dob, yob);
statusText = getStatusText(statusCode);
}
private static int[] locateDelimiters(byte[] msgInBytes) {
int[] delimiters = new int[NUMBER_OF_PARAMS_IN_SECURE_QR_CODE + 1];
int index = 0;
int delimiterIndex;
for (int i = 0; i <= NUMBER_OF_PARAMS_IN_SECURE_QR_CODE; i++) {
delimiterIndex = getNextDelimiterIndex(msgInBytes, index);
delimiters[i] = delimiterIndex;
index = delimiterIndex + 1;
}
return delimiters;
}
private static String getValueInRange(byte[] msgInBytes, int start, int end) {
return new String(Arrays.copyOfRange(msgInBytes, start, end), Charset.forName("ISO-8859-1"));
}
private static int getNextDelimiterIndex(byte[] msgInBytes, int index) {
int i = index;
for (; i < msgInBytes.length; i++) {
if (msgInBytes[i] == -1) {
break;
}
}
return i;
}
private static byte[] decompressByteArray(byte[] bytes) throws IOException {
java.io.ByteArrayInputStream bytein = new ByteArrayInputStream(bytes);
java.util.zip.GZIPInputStream gzin = new GZIPInputStream(bytein);
java.io.ByteArrayOutputStream byteout = new ByteArrayOutputStream();
int res = 0;
byte buf[] = new byte[1024];
while (res >= 0) {
res = gzin.read(buf, 0, buf.length);
if (res > 0) {
byteout.write(buf, 0, res);
}
}
return byteout.toByteArray();
}
private String formatDate(String rawDateString, String[] possibleFormats) {
if (rawDateString.equals("")) {
return "";
}
SimpleDateFormat toFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
ParseException parseException = null;
for (String fromFormatPattern : possibleFormats) {
try {
SimpleDateFormat fromFormat = new SimpleDateFormat(fromFormatPattern);
date = fromFormat.parse(rawDateString);
break;
} catch (ParseException e) {
parseException = e;
}
}
if (date != null) {
return toFormat.format(date);
} else if (parseException != null) {
System.err.println("Expected dob to be in dd/mm/yyyy or yyyy-mm-dd format, got " + rawDateString);
return rawDateString;
} else {
throw new AssertionError("This code is unreachable");
}
}
#NonNull
protected String formatGender(String gender) throws ParseException {
String lowercaseGender = gender.toLowerCase();
if (lowercaseGender.equals("male") || lowercaseGender.equals("m")) {
return "M";
} else if (lowercaseGender.equals("female") || lowercaseGender.equals("f")) {
return "F";
} else if (lowercaseGender.equals("other") || lowercaseGender.equals("o")) {
return "O";
} else {
throw new ParseException("404 gender not found", 0);
}
}
#NonNull
private String getStatusText(int statusCode) {
switch (statusCode) {
case ScanResult.STATUS_SUCCESS:
return "✓";
default:
return "✗";
}
}
#NonNull
private String getDobGuess(String dob, String yob) {
if (dob.equals("")) {
Integer yearInt;
try {
yearInt = Integer.parseInt(yob);
} catch (NumberFormatException e) {
return "";
}
// June 1 of the year
return Integer.toString(yearInt) + "-06-01";
} else {
return dob;
}
}
Github Code Link
Just now got the solution, fetched exact mobile and email hash value from byte array
first remove last 256 bytes from byte array then,
if only mobile present then take last 32 bytes from byte array for mobile
i.e. (array.length - 32 to array.length)
else if only email present then take last 32 bytes from byte array for email i.e. (array.length - 32 to array.length)
else if both email and mobile present then take last 32 bytes from byte array for mobile, take next last 32 bytes for email
i.e. (mobile = array.length - 32 to array.length and
email = array.length - 64 to array.length - 32)
From the byte array you need to read values from index byte_array_length - 256 - 32 to byte_array_length - 256 to get the mobile hash in bytes(you can easily convert the bytes to hexadecimal string) and similarly for email you need to read from index byte_array_length - 256 - 32 - 32 to byte_array_length - 256 - 32.
I have implemented a library for decoding the same but the implementation is in Python.
The question is a bit old but future readers might find these resources useful.
PyPI: aadhaar-py
Github: https://github.com/vishaltanwar96/aadhaar-py

Extract weather forecast data from NetCDF 4.5 Grib2Record

Update: Changed this question to better reflect my current understanding.
I have a NetCDF version 4.5 Grib2Record object. Given a (x,y) grid point and a variable name I want to extract all the forecast data for that variable by forecast-time from the object (if the record contains the forecast for that variable). Because of the default behavior of writing a disk index file I do not want to use the higher level NetCDFFile interface.
I have tried looking at lower level code (Grib2Rectilyser, Grib2Customizer etc.) But the code is too dense and I am looking for help with where to start.
I would appreciate any pointers on how to take a Grib2Record and 1. check whether a particular forecast variable is contained in it, and 2. if it is, then extract the forecast data by forecast-valid-time for a given x-y grid point and z-level.
I have worked with grib2 files for wind predictions, this is how I get the records and how to process it to get wind (V U components)
Grib2Input input = new Grib2Input(getRandomAccessFile());
if (!input.scan(false, false)) {
logger.error("Failed to successfully scan grib file");
return;
}
Grib2Data data = new Grib2Data(getRandomAccessFile());
List<Grib2Record> records = input.getRecords();
for (Grib2Record record : records) {
Grib2IndicatorSection is = record.getIs();
Grib2IdentificationSection id = record.getId();
Grib2Pds pdsv = record.getPDS().getPdsVars();
Grib2GDSVariables gdsv = record.getGDS().getGdsVars();
long time = id.getRefTime() + (record.getPDS().getForecastTime() * 3600000);
logger.debug("Record description at " + pdsv.getReferenceDate() + " forecast "
+ new Date(time) + ": " + ParameterTable.getParameterName(is.getDiscipline(), pdsv.getParameterCategory(), pdsv.getParameterNumber()));
float[] values = data.getData(record.getGdsOffset(), record.getPdsOffset(), 0);
if ((is.getDiscipline() == 0) && (pdsv.getParameterCategory() == 2) && (pdsv.getParameterNumber() == 2)) {
// U-component_of_wind
int c = 0;
for (double lat = gdsv.getLa1(); lat >= gdsv.getLa2(); lat = lat - gdsv.getDy()) {
for (double lon = gdsv.getLo1(); lon <= gdsv.getLo2(); lon = lon + gdsv.getDx()) {
logger.debug(lat + "\t" + lon + "\t" +
values[c]);
c++;
}
}
} else if ((is.getDiscipline() == 0) && (pdsv.getParameterCategory() == 2) && (pdsv.getParameterNumber() == 3)) {
// V-component_of_wind
int c = 0;
for (double lat = gdsv.getLa1(); lat >= gdsv.getLa2(); lat = lat - gdsv.getDy()) {
for (double lon = gdsv.getLo1(); lon <= gdsv.getLo2(); lon = lon + gdsv.getDx()) {
logger.debug(lat + "\t" + lon + "\t" +
values[c]);
c++;
}
}
}
}
private RandomAccessFile getRandomAccessFile() {
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(path, "r");
raf.order(RandomAccessFile.BIG_ENDIAN);
} catch (IOException e) {
logger.error("Error opening file " + path, e);
}
return raf;
}

Faster data transfer to postgreSQL using Java?

I am curious to if there is an faster way to transfer data from a file, to my postgreSQL database. I am using java. The files are GRIB files, so basically weather type files. I have created a text file where I would go grab the name of the file Im looking for and use it to grab my data then send that data into my database. Can someone give me a hint to what I should to improve my speed?
public class JgribDEXcopy{
// Global variables
static GribFile gribfile;
static int numOFrecords;
static int numOFgds;
protected static int eventX;
protected static int eventY;
protected static int xIA = 543;
protected static int yIA = 451;
protected static int xIAend = 703;
protected static int yIAend = 591;
private static Connection connection = null;
private static PreparedStatement state = null;
static String st;
static int k, l, in = 0;
static File file = new File("E:/IFIC/2009.txt");
// Gets the number of records in the GRIB file
// Prints out that number for testing the correct amount of records
public static void read(GribFile n){
numOFrecords = n.getRecordCount();
//System.out.println("HELLO: " + numOFrecords + " & " + numOFgds + " Is the magic number");
}
public static void main(String[] args) throws ClassNotFoundException, SQLException, NoSuchElementException, IOException{
BufferedReader br = new BufferedReader(new FileReader(file));
String line = "";
while((line = br.readLine()) != null){
int counter = 0;
// Connecting to the database
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection("jdbc:postgresql://database/database","username", "password");
String nline = "E:/IFIC/IIHS_data/ST4." + line + ".01h.grb";
// Reading of grib files must be inside a try-catch block
try{
// Create GribFile instance
gribfile = new GribFile(nline);
read(gribfile);
// Dump verbose inventory for each record
//gribfile.listRecords(System.out);
// Dumps the grid/s into an array
GribRecordGDS[] arr = gribfile.getGrids();
float arrBDS;
// Gets the Width and Height of the grid
// Calculates the number of points in the grid
eventX = arr[0].getGridNX();
eventY = arr[0].getGridNY();
numOFgds = eventX * eventY;
//System.out.println(numOFgds);
//System.out.println(eventX);
//System.out.println(eventY);
// Creates a writer that will print to a file
//PrintWriter writer = new PrintWriter("ST4.2014030123.01h.txt", "UTF-8");
//System.out.println((int) (gribfile.getRecord(1).getTime().getTime().getTime()/1000));
// Filters for the area Iowa Flood Center deals with (which is basically Iowa area)
// Takes the database connection and inserts the necessary data
for(int i = 0; i <= eventX; i++){
for(int j = 0; j <= eventY; j++){
if(i >= xIA && i <= xIAend && j <= yIAend && j >= yIA){
arrBDS = gribfile.getRecord(1).getValue(i, j);
if(arrBDS != 0.000){
k = i;
l = j;
in = 1000 * (k+1) + (l+1);
//writer.println(i + "," + j + "," + arrBDS);
//System.out.println(in + "," + arrBDS);
// st = "INSERT INTO master_st4(unix_timestamp, hrap_xy, rain) values(?, ?, ?)";
// //System.out.println((int)(gribfile.getRecord(1).getTime().getTime().getTime()/1000));
//
// state = connection.prepareStatement(st);
// state.setInt(1, (int) (gribfile.getRecord(1).getTime().getTime().getTime()/1000));
// state.setInt(2, in);
// state.setDouble(3, arrBDS);
// state.executeUpdate();
}
// Keeps track of all the X, Y coordinates with zero rainfall
if(arrBDS == 0.0){
counter++;
}
}
}
}
System.out.println("There is " + counter + " number of zero's");
//writer.close();
}
catch (FileNotFoundException noFileError){
System.err.println("FileNotFoundException : " + noFileError);
}
catch (IOException ioError){
System.err.println("IOException : " + ioError);
}
catch (NoValidGribException noGrib){
System.err.println("NoValidGribException : " + noGrib);
}
catch (NotSupportedException noSupport){
System.err.println("NotSupportedException : " + noSupport);
}
// closes database connection
connection.close();
}
br.close();
}
}
Bulk-load the data using the PgJDBC COPY API. Failing that, at least do multi-valued inserts grouped into transactions.
See:
How to speed up insertion performance in PostgreSQL
http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/PGConnection.html - PGConnection and the CopyManager.

How to convert latitude and longitude from decimal dms to degree in java

I receive the latitude and longitude from a GPS with this format:
Latitude: 3328.21103S
Longitude: 07043.64734W
I need convert this data to:
Latitude: -33.4701838
Longitude: -70.7274557
How to convert this data in java?
Thanks .
Best Regards.
I solved this way:
1- Separate lattitude and longitude in degree, minutes, seconds, direction(N,S,W,E)
2- Send degree, minutes, seconds, direction to method DMSaDecimal this return: latitude or longitude in decimal
public double DMSaDecimal(int grados, int minutos, double segundos, String direccion) {
double decimal = Math.signum(grados) * (Math.abs(grados) + (minutos / 60.0) + (segundos / 3600.0));
//reverse for south or west coordinates; north is assumed
if (direccion.equals("S") || direccion.equals("W")) {
decimal *= -1;
}
return decimal;
}
public String[] SeparararDMS(String coordenada, int type) {
String grados = null;
String minutos = null;
String segundos = null;
String direccion = null;
switch (type) {
case 1: // latitude
grados = coordenada.substring(0, 2);
minutos = coordenada.substring(2, 4);
segundos = coordenada.substring(5, coordenada.length() - 1);
break;
case 2: // longitude
grados = coordenada.substring(0, 3);
minutos = coordenada.substring(3, 5);
segundos = coordenada.substring(6, coordenada.length() - 1);
break;
default:
}
double sec = 0;
try {
sec = Double.parseDouble("0."+segundos);
}catch(Exception e) {
}
sec = (sec * 60);
direccion = coordenada.substring(coordenada.length() - 1);
String[] data = {grados, minutos, sec + "", direccion};
return data;
}
Using arcgis:
public static void convertCoordDMS(){
try{
// create coordinate object for degrees, minutes, seconds format
DMSCoordinate dmsCoord = new DMSCoordinate();
dmsCoord.setString("37 -123 32 34.43"); // put a string value
String dms = dmsCoord.getString(); // get back the normalized DMS string
System.out.println("Input (string): (\"37 -123 32 34.43\")");
System.out.println("Output (normalized string): " + dms + '\n');
// now for decimal degrees
DDCoordinate ddCoord = new DDCoordinate();
// put in the Point from dmsCoord. The Point property is
// “common ground” for all Coordinate objects
IPoint point = null;
ddCoord.setPoint(dmsCoord.getPoint());
// get back the normalized DD string
String dd = ddCoord.getString();
System.out.println("Input (Point): same as DMS");
System.out.println("Output (normalized string): " + dd + '\n');
// and the coordinate as lon lat doubles
double[] x = new double[25];
double[] y = new double[25];
ddCoord.getCoords(x, y);
System.out.println("Input (Point): same as DMS");
System.out.println("Output (Lat Lon): " + x + " " + y);
}
catch (Exception ex){
ex.printStackTrace();
}
}
If you're interested in knowing more, wikipedia is a good place to start.

How to convert serialClob to String format?

I am trying to convert serialclob to string. But I am not successful. I think I am not doing in the correct way. My code is:
char[] buffer;
int count = 0;
int length = 0;
String data = null;
String[] type;
StringBuffer sb;
try{
SqlRowSet rows = getJdbcTemplate().queryForRowSet("select c.BOUNDING_BOX.GET_WKT() BOUNDING_BOX FROM EXAMPLE c WHERE EXAMPLE_ID = 100",
new Object[] {subid});
SubscriptionModel subscription = new SubscriptionModel();
System.out.println("bbox");
SqlRowSetMetaData rsmd = rows.getMetaData();
type = new String[rsmd.getColumnCount()];
for(int col=0;col<rsmd.getColumnCount();col++)
type[col] = rsmd.getColumnTypeName(col + 1);
System.out.println("Read rows and only serial clob data type values");
while(rows.next()){
System.out.println("test 1 here");
for(int col=0;col<rsmd.getColumnCount();col++){
System.out.println("test 2 here");
if("CLOB".equals(type[col]){
System.out.println("test 3 here");
SerialClob clob = (SerialClob) ((ResultSet) rows).getClob(col + 1);
if(clob != null){
System.out.println("clob is not null");
Reader is = clob.getCharacterStream();
sb = new StringBuffer();
length = (int) clob.length();
if(length>0){
buffer = new char[length];
count = 0;
try{
while((count = is.read(buffer)) != -1)
sb.append(buffer);
data = new String(sb);
}catch(Exception e){
}
}
else
data = (String) null;
}else
data = (String) null;
}else{
data = (String) rows.getObject(col + 1);
}
}
}
return subscription;
}catch(Exception e){
e.printStackTrace();
}
But I am getting an error like:
bbox
Read rows and only serial clob data type values
test 1 here
test 2 here
java.lang.ClassCastException: javax.sql.rowset.serial.SerialClob cannot be cast to java.lang.String
Where is my mistake?
Well this is at least one problem:
if(type[col] == "CLOB")
That's comparing string references directly. I suspect this would work better:
if ("CLOB".equals(type[col]))
That will get you into the right if block. I haven't looked in detail at the rest of your code - it would be simpler to read and maintain if you could break it up into smaller methods.
The problem is most likely here --
if(type[col] == "CLOB"){ // <-- This does Object equality
Use String#equals() method to do String comparisons.
if ( "CLOB".equals(type[col]) ) {

Categories