Si avevi ragione. Adesso sto provando a fare il SELECT di ciò che ho messo nella tabella ma comunque non va
package javadb;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
/**
*
* @author valerio
*/
public class JavaDB {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
//createTable();
//insert();
get();
}
public static void get() throws Exception {
try{
String attributo;
int id;
Connection conn = getConnection();
PreparedStatement stmt = conn.PreparedStatement("SELECT id, attributo FROM tablename6 WHERE id = ?");
stmt.setString(1, "1");
ResultSet rs = stmt.executeQuery();
while(rs.next()){
id = rs.getInt(1);
attributo = rs.getString(2);
System.out.println("Id = "+id+"Attributo = "+attributo);
}
stmt.close();
}catch(Exception e){
System.out.println(e);
}finally{
System.out.println("Operazione riuscita!");
}
}
public static void insert() throws Exception{
final int id = 1;
final String attributo = "Moto";
try{
Connection conn = getConnection();
PreparedStatement inserted = conn.prepareStatement("INSERT INTO tablename6 VALUES (?,?)");
inserted.setInt(1, id);
inserted.setString(2, attributo);
inserted.executeUpdate();
}catch (Exception e){
System.out.println(e);
}finally{
System.out.println("Inserimento completato");
}
}
public static createTable() throws Exception{
try{
Connection conn = getConnection();
PreparedStatement create = conn.prepareStatement("CREATE TABLE tablename6(id number PRIMARY KEY, attributo VARCHAR2(60))");
create.executeUpdate();
}catch(Exception e){
System.out.println(e);
}finally{
System.out.println("Funzione completata");
}
}
public static Connection getConnection() throws Exception {
try{
String url="jdbc:oracle:thin:@localhost:1522:Orcl";
String user = "SYSTEM";
String pw = "Scarpone2";
Connection conn = null;
conn = DriverManager.getConnection(url,user,pw);
System.out.println("Connesso!");
return conn;
}catch(Exception e){
System.out.println("Errore: " + e);
}
return null;
}
}
il ritorno è questo:
Connesso!
java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.sql.Connection.PreparedStatement
Operazione riuscita!
BUILD SUCCESSFUL (total time: 2 seconds)