Hibernate使用sql进行查询,没有映射的情况
答案:1 悬赏:0 手机版
解决时间 2021-02-15 10:21
- 提问者网友:寂寞梧桐
- 2021-02-14 13:00
sql="select distinct phone,count(*) as count from tp_data where qydm='10000' group by phone "; cql="select count(distinct phone) as count from tp_data where qydm='10000' "; 查询: Connection con=session.connection(); Statement stm=con.createStatement(); ResultSet result=stm.executeQuery(sql); 但是报错了 java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'tp_data' 无效。 请高手知道
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-02-14 13:28
呵呵,不用hibernate的话,你还这样Connection con=session.connection();得到con, 当然不行了啊,使用JDBC的话,你就应该这样得到con啊.. public class SQLConnect { private Connection con ; private CallableStatement cstmt; private String drivername; private String url; private String user; private String password; public SQLConnect(){ drivername = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=testDB"; user = "sa"; password = "123456"; } public Connection getConn() throws Exception{ try{ Class.forName(drivername); con = DriverManager.getConnection(url,user,password); return con; }catch(SQLException e){ System.out.println(e.getMessage()); throw e; } } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯