***************************************************************************02:42:50,437 DEBUG JDBCTransaction:54 - begin
02:42:50,437 DEBUG ConnectionManager:421 - opening JDBC connection
02:42:50,437 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
02:42:50,437 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
02:42:50,437 DEBUG JDBCTransaction:59 - current autocommit status: false
02:42:50,437 DEBUG JDBCContext:210 - after transaction begin
02:42:50,468 DEBUG QueryPlanCache:112 - unable to locate native-sql query plan in cache; generating (from Groups g)
02:42:50,484 DEBUG SQLCustomQuery:62 - starting processing of sql query [from Groups g]
02:42:50,500 DEBUG SessionImpl:1685 - SQL query: from Groups g
02:42:50,515 DEBUG AbstractBatcher:366 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
02:42:50,515 DEBUG SQL:401 - from Groups g
02:42:50,515 DEBUG AbstractBatcher:484 - preparing statement
02:42:50,546 DEBUG AbstractBatcher:374 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
02:42:50,546 DEBUG AbstractBatcher:533 - closing statement
02:42:50,593 DEBUG JDBCExceptionReporter:69 - could not execute query [from Groups g]
java.sql.SQLException: 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 'from Groups g' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3026)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1137)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1231)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at Test.loadAllGroups(Test.java:67)
at Test.main(Test.java:83)
02:42:50,593  WARN JDBCExceptionReporter:77 - SQL Error: 1064, SQLState: 42000
02:42:50,593 ERROR JDBCExceptionReporter:78 - 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 'from Groups g' at line 1
02:42:50,593 DEBUG JDBCTransaction:152 - rollback
02:42:50,593 DEBUG JDBCTransaction:163 - rolled back JDBC Connection
02:42:50,593 DEBUG JDBCContext:215 - after transaction completion
02:42:50,593 DEBUG ConnectionManager:404 - aggressively releasing JDBC connection
02:42:50,593 DEBUG ConnectionManager:441 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
02:42:50,593 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
02:42:50,593 DEBUG SessionImpl:422 - after transaction completion
02:42:50,593 DEBUG SessionImpl:273 - closing session
02:42:50,593 DEBUG ConnectionManager:375 - connection already null in cleanup : no action
jlive
jlive
***************************************************************************
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction; import Config.HibernateUtil;
import forms.Users;
public class Test {
public void loadAllGroupsByJDBC(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection con=null;
try {
con=DriverManager.getConnection("jdbc:mysql://localhost/bbs","root","");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PreparedStatement ps=null;
try {
 ps=con.prepareStatement("select * from groups");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet rs=null;
try {
  rs=ps.executeQuery();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
while(rs.next())
System.out.println(rs.getString("groupname"));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 

}
public List loadAllGroups(Users user) {
// TODO Auto-generated method stub
Session session = HibernateUtil.getCurrentSession();
Transaction tx = null;
List results = null;
try {
tx = session.beginTransaction();
Query query = session.createSQLQuery("from Groups g");
results = query.list();
} catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
} } finally {
// No matter what, close the session
session.close();
} return results;
}
public  static void main(String args[]){
Test test=new Test();
test.loadAllGroups(null);
test.loadAllGroupsByJDBC();
}}