我是新手打开jpa环境,我需要将jdbc代码转换为打开jpa,请帮我解决这个问题。我发布了这篇文章的jdbc代码。
//error.java//
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class ErrorDAO
{
DataConnection jdbcConnection = null;
public ErrorDAO()
{
jdbcConnection = new DataConnection();
}
public static void main(String[] args) {
ErrorDAO errorDAO = new ErrorDAO();
long errid = errorDAO.getErrorId("POTENTIAL VIOLATION");
String[] details = errorDAO.getErrorDetails(errid);
System.out.println(details[0]);
System.out.println(details[1]);
}
public String[] getErrorDetails(long errid)
{
String[] details = new String[2];
System.out.println("The input error id = " + errid);
try {
Connection connection = jdbcConnection.getConnectionInstance();
Statement stmt = connection.createStatement();
String query = "SELECT * FROM VARBALAS.ERROR_MASTER WHERE ERRORID = "+errid;
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
details[0] = rs.getString("ERRDESC");
details[1] = rs.getString("SEVERITY");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return details;
}
public long getErrorId(String errDesc)
{
long errid = 0 ;
try {
Connection connection = jdbcConnection.getConnectionInstance();
Statement stmt = connection.createStatement();
String query = "SELECT ERRORID FROM VARBALAS.ERROR_MASTER WHERE ERRDESC = '"+errDesc+"'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
errid = rs.getLong("ERRORID");
}
System.out.println("Printing the queried ERROR id "+errid);
System.out.println("End of Data");
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return errid;
}
}