Connection's Method to Print Native SQL : Connection « Database « Java Tutorial






import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    conn.setAutoCommit(false);
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,myURL CHAR);");

    String str = conn.nativeSQL("insert into survey(id) values(02)");

    System.out.println(str);
    
    conn.commit();    
    st.close();
    conn.close();
  }

  private static Connection getConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    return DriverManager.getConnection(url, "sa", "");
  }
}








20.3.Connection
20.3.1.Connection Object
20.3.2.Connection Object Requirements
20.3.3.Connection Properties: Pass additional properties using java.util.Properties:
20.3.4.Passing 'user' and 'password' Parameters as a java.util.Properties Object to Connection object
20.3.5.Test to See if Your Connection is Alive
20.3.6.Vendor URL Formats
20.3.7.Connection's Method to Print Native SQL