데이터베이스 연결을 성공적으로 설정했지만 Java를 통해이 코드를 실행할 때 코드가 계속 실행되고 아무 일도 일어나지 않습니다. 아무것도 데이터베이스에 삽입하거나 아무런 예외도주지 않는다는 것을 의미하지 않습니다.JDBC 삽입 쿼리가 오라클 데이터베이스에 레코드를 삽입하지 않습니다.
Oracle 11g (MDSYS.SDO_POINT_TYPE)의 공간 데이터 유형을 사용하고 있습니다. Oracle 11g 데이터베이스에서이 쿼리를 직접 실행했지만 정상적으로 작동하지만 Java 코드를 통해 레코드를 삽입하면 어떻게 든 삽입되지 않습니다.
간단한 학생용 테이블을 사용해 보았고 java를 사용하여 문장을 삽입 할 수있었습니다.
String insert = "insert into table1 values('p0', MDSYS.SDO_POINT_TYPE(228,102, null))";
try
{
Statement statement = connection.createStatement();
statement.executeUpdate(insert);
System.out.println("Inserted record in the table");
}catch(SQLException e)
{
System.out.println("Error due to SQL Exception");
e.printStackTrace();
}
try
{
connection.close();
System.out.println("Closing the connection");
}catch(SQLException e)
{
System.out.println("Error in closing connection");
e.printStackTrace();
}
연결 JDBC는 다음과 같습니다 : 여기
내 조각이다try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:db11g", username,
pass);
} catch (SQLException e) {
System.out.println("Connection Failed!");
e.printStackTrace();
}
if (connection != null) {
System.out.println("Database connected");
} else {
System.out.println("Failed to connect the database");
}
return connection;
할 수 있습니까 DB에서 먼저 동일한 삽입 쿼리를 실행하고 작동하는지 확인하십시오? 이 방법을 사용하면 쿼리에 문제가 있는지 또는 자바 코드인지 나중에 알 수 있습니다. – Lokesh
예 데이터베이스에 직접 삽입 할 때 작동합니다. – user16666
연결 설정은 어떻게되어 있습니까? 그것을 잡으려고 커밋을해야합니까? –