mysql_insert_id () no Java

Em php quando eu gravo um registro no banco eu uso a função mysql_insert_id () para pegar o id do registro inserido evitando que eu tenha que realizar uma consulta.

Existe uma função semelhante no java?

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#getGeneratedKeys()

Valeu pela dica. Consegui achar o que eu queria.

S´que surgiu outro problema, na última linha do método existe um erro que eu não estou encontrando solução.

	 public void insert(EscolaT escolaT ) throws Exception { 
		 String sql = "insert into escola  (razao_social, nome_fantasia, cnpj, insc_social, endereco, numero, complemento, city_id, cep, telefone, fax, email, data_inscricao) values (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
		 PreparedStatement pStmt = con.prepareStatement(sql);
		 pStmt.setObject(1, escolaT.getIdescola());
		 pStmt.setObject(2, escolaT.getRazao_social());
		 pStmt.setObject(3, escolaT.getNome_fantasia());
		 pStmt.setObject(4, escolaT.getCnpj());
		 pStmt.setObject(5, escolaT.getInsc_social());
		 pStmt.setObject(6, escolaT.getEndereco());
		 pStmt.setObject(7, escolaT.getNumero());
		 pStmt.setObject(8, escolaT.getComplemento());
		 pStmt.setObject(9, escolaT.getCity_id());
		 pStmt.setObject(10, escolaT.getCep());
		 pStmt.setObject(11, escolaT.getTelefone());
		 pStmt.setObject(12, escolaT.getFax());
		 pStmt.setObject(13, escolaT.getEmail());
		 java.sql.Date dt14= new java.sql.Date(escolaT.getData_inscricao().getTime());
		 pStmt.setObject(14, dt14);
		 int val = pStmt.executeUpdate(sql, autoGeneratedKeys);
         
 	 }
int val = pStmt.executeUpdate();

Eu não estou conseguindo achar a forma certa de pegar o id do registro inserido.

Eu testei o int val = pStmt.executeUpdate() que pmlm me disse só que a variavel val somente recebe o valor 1.

Quando eu executo o código abaixo dispara um erro:
int autoGeneratedKeys = 0;
int val = pStmt.executeUpdate(sql, autoGeneratedKeys);

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )’ at line 1
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )’ at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.escola_jsp._jspService(escola_jsp.java:241)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )’ at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
com.mysql.jdbc.Connection.execSQL(Connection.java:3118)
com.mysql.jdbc.Statement.executeUpdate(Statement.java:1313)
com.mysql.jdbc.Statement.executeUpdate(Statement.java:1232)
com.mysql.jdbc.Statement.executeUpdate(Statement.java:1385)
DAO.EscolaDAO.insert(EscolaDAO.java:40)
org.apache.jsp.escola_jsp._jspService(escola_jsp.java:175)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18

int val = pStmt.executeUpdate(); //executa o insert. Val fica com o numero de linhas inseridas (1) ResultSet keys = pStmt.getGeneratedKeys(); //ResultSet fica com as keys geradas