He estado buscando por el foro acerca del error que me salta en java pero no he encontrado algo similar.
Tengo dos tablas que pertenecen a una misma base de datos(datos): jena_g1t1_stmt
Código:
y jena_long_lit+---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | Subj | varchar(100) | NO | MUL | NULL | | | Prop | varchar(100) | NO | | NULL | | | Obj | varchar(100) | NO | MUL | NULL | | | GraphID | int(11) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+
Código:
+--------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Head | varchar(100) | NO | MUL | NULL | | | ChkSum | bigint(20) | YES | | NULL | | | Tail | mediumblob | YES | | NULL | | +--------+--------------+------+-----+---------+----------------+
Por otra parte tengo otra base de datos (resultados) donde quiero hacer inserciones en una tabla llamada ontologia
Código:
Lo que quiero hacer es insertar el Subj, Prop y GraphID de la tabla jena_g1t1_stmt , en el caso del Obj insertare un valor, dependiendo de si coincide o nocon el ID de jena_long_lit.+-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | ID | int(11) | NO | | NULL | | | Sujeto | varchar(100) | NO | | NULL | | | Propiedad | varchar(100) | NO | | NULL | | | Objeto | varchar(100) | NO | | NULL | | | Comentario1 | varchar(100) | YES | | NULL | | | Comentario2 | mediumblob | YES | | NULL | | +-------------+--------------+------+-----+---------+-------+
Comentario1 y Comentario2 de ontologia se corresponden con Head y Tail de jena_long_lit respectivamente.
La cuestión es que he desarrollado el siguiente código:
Código:
Y como error me aparece el siguiente:private void tratarTablas(){
try
{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection conexion1 = DriverManager.getConnection (
"jdbc:mysql://localhost:3306/datos","root", "xxx");
Connection conexion2 =DriverManager.getConnection(
"jdbc:mysql://localhost:3306/datos","root", "xxx");
Connection conexion3 = DriverManager.getConnection (
"jdbc:mysql://localhost:3306/resultados","root", "xxx");
Statement stat = conexion1.createStatement();
Statement stat2 =conexion2.createStatement();
ResultSet rs1 = stat.executeQuery ("select * from jena_g1t1_stmt");
ResultSet rs2 = stat2.executeQuery ("select * from jena_long_lit");
PreparedStatement stmt=null;
int id;
String sujeto;
String propiedad;
String objeto;
String comentario1;
Blob comentario2=null;
int buscado;
int intObjeto=0;
String objetoAux=new String();
boolean dentro;
while (rs1.next())
{
stmt = conexion3.prepareStatement
("INSERT INTO ontologia VALUES (?,?,?,?,?,?)");
id=(Integer)rs1.getObject(4); //primer campo
sujeto=rs1.getObject(1)); //segundo campo
propiedad=rs1.getObject(2)); //tercer campo
objeto=(String)rs1.getObject(3);
if (objeto.contains("Lr:")){
dentro=true;
while (dentro||rs2.next()){
objetoAux=tc.tratarCampo(objeto);//Obtengo un numero que está dentro de objeto
intObjeto=Integer.parseInt(objetoAux);//Convierto a int el número obtenido en la línea anterior
buscado=rs2.getInt(1);
if (intObjeto==buscado){//Aqui es donde falla, o eso creo
dentro=false;
comentario1=(String)rs2.getObject(2);
comentario2=rs2.getBlob(4);
}
}
}else{
comentario1=new String();
comentario2=null;
}
stmt.setInt(1,id);
stmt.setString(2,sujeto);
stmt.setString(3, propiedad);
stmt.setString(4, objeto);
stmt.setString(5, comentario1);
stmt.setBlob(6, comentario2);
stmt.executeUpdate();
}
conexion1.close();
conexion2.close();
conexion3.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Código:
¿Alguien me podría decir porque ocurre?java.sql.SQLException: Before start of result set
Espero que alguien me pueda echar una mano con este código que me está jod..., también espero haberme explicado bien.
Gracias adelantadas.
Saludos.

Este tema le ha gustado a 1 personas