精华内容
下载资源
问答
  • python连接mysql并执行SQL语句的方法步骤:1.创建与数据库连接对象2.建立游标对象3.利用游标对象 执行SQL语句命令4.#提交到数据库5.关闭游标对象6.关闭数据库连接7.建立一个Mysqlpython 类 实现数据库的连接 关闭 和...

    python连接mysql并执行SQL语句的方法步骤:

    1.创建与数据库连接对象

    2.建立游标对象

    3.利用游标对象 执行SQL语句命令

    4.#提交到数据库

    5.关闭游标对象

    6.关闭数据库连接

    7.建立一个Mysqlpython 类 实现数据库的连接 关闭 和执行SQL语句操作,实现对数据库连接的封装

    实现代码:import pymysql

    #1.创建与数据库连接对象

    db =pymysql.connect(host="localhost",user="root",

    password="123456",database="db4",

    charset="utf8")

    #2.利用db方法创建游标对象

    cur = db.cursor()

    #3.利用游标对象execute()方法执行SQL命令

    #cur.execute(";") #这里填写正确的SQL语句  例如:

    cur.execute("insert into sheng values

    (16,300000,'台湾省');")

    #4.提交到数据库执行

    db.commit()

    print("OK")

    #5.关闭游标对象

    cur.close()

    #6.断开数据库连接

    db.close()

    更多Python知识请关注云海天python教程网。

    展开全文
  • sequel pro怎么执行sql语句

    千次阅读 2018-10-18 07:45:22
    输入sql语句,然后按ctrl+r就可以执行

    输入sql语句,然后按ctrl+r就可以执行。

    展开全文
  • java中怎么执行sql语句

    2017-08-20 08:54:06
    如图我想在 java代码的方法里执行这条sql插入语句,把一条记录save进oracle数据库,菜鸟不知道怎么写,求帮助![图片说明](https://img-ask.csdn.net/upload/201708/20/1503219228_332645.png)
  • getHibernateTemplate()方法怎么执行sql语句  2010-04-06 13:45:09| 分类: 程序代码类|字号 订阅 方法一: 获取一个Connection: Connection conn = getHibernateTemplate()....

    getHibernateTemplate()方法怎么执行sql语句  

    2010-04-06 13:45:09|  分类: 程序代码类|字号 订阅

    方法一:

    获取一个Connection:

    Connection conn = getHibernateTemplate().getSessionFactory().openSession().connection(); 
    Statement st=conn.createStatement();

    st.execute("select * from tablename");

    最后关闭链接:

    finally{
       try{
        if(st!=null)
         st.close();
        if(conn!=null)
         conn.close();
       }catch(SQLException e){
        System.out.println(e.toString());
       }
      }
    方法二(未验证):

    使用spring中的回调机制,例如下面这个例子是我在项目中用来修改密码的方法

    public int modifyPwd(final String oldPwd , final String newPwd)

    {

    return (Integer)getHibernateTemplate().execute(new HibernateCallback() {

    public Object doInHibernate(Session session) throws HibernateException {

    Query query = session.createQuery("update SysUsers set userPwd = :newPwd where userPwd =ldPwd");

    query.setParameter("newPwd", newPwd);

    query.setParameter("oldPwd", oldPwd);

    return query.executeUpdate();

    }

    });

    }

    展开全文
  • [img=https://img-bbs.csdn.net/upload/202003/14/1584160089_647571.png]... 我在一个页面写好了gridview(绑定了订单表),添加一个按钮(后面想写查询方法) ... ...请问下具体那一步步要用什么方法。...我用的是webform
  • 我的项目是用struts hibernate 还有spring 组合的可是当我执行这个事务的时候 我的sql 语句无法执行public User findByEmail(String name , String password){String hql = "from com.buat.model.User";Query query ...

    我的项目是用struts  hibernate 还有spring 组合的

    可是当我执行这个事务的时候 我的sql 语句无法执行

    public User findByEmail(String name , String password){

    String hql = "from com.buat.model.User";

    Query query =this.getSession().createSQLQuery(hql);

    List list = query.list(); //这里无法执行

    User user = list.get(0);

    return user ;

    }

    这是我的控制台所报的错误

    严重: Servlet.service() for servlet action threw exception

    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 'from com.buat.model.User' at line 1

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)

    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)

    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

    at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)

    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)

    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1262)

    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)

    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)

    at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)

    at org.hibernate.loader.Loader.doQuery(Loader.java:662)

    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

    at org.hibernate.loader.Loader.doList(Loader.java:2144)

    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)

    at org.hibernate.loader.Loader.list(Loader.java:2023)

    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:150)

    at com.buat.service.UserManager.findByEmail(UserManager.java:20)

    at com.buat.service.UserManager$$FastClassByCGLIB$$3c143d2e.invoke()

    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:714)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)

    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:652)

    at com.buat.service.UserManager$$EnhancerByCGLIB$$684b62ee.findByEmail()

    at com.buat.action.BookAction.validatorUser(BookAction.java:73)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:585)

    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)

    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)

    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)

    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)

    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)

    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

    at java.lang.Thread.run(Thread.java:595)

    2009-04-16 19:14:28,531 ERROR [/springside/bookManager.do] -

    javax.servlet.ServletException: org.hibernate.exception.SQLGrammarException: could not execute query

    at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)

    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)

    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)

    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)

    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

    at java.lang.Thread.run(Thread.java:595)

    Caused by: org.hibernate.exception.SQLGrammarException: could not execute query

    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)

    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

    at org.hibernate.loader.Loader.doList(Loader.java:2147)

    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)

    at org.hibernate.loader.Loader.list(Loader.java:2023)

    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:150)

    at com.buat.service.UserManager.findByEmail(UserManager.java:20)

    at com.buat.service.UserManager$$FastClassByCGLIB$$3c143d2e.invoke()

    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:714)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)

    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)

    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:652)

    at com.buat.service.UserManager$$EnhancerByCGLIB$$684b62ee.findByEmail()

    at com.buat.action.BookAction.validatorUser(BookAction.java:73)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:585)

    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)

    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)

    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)

    ... 25 more

    Caused by: 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 'from com.buat.model.User' at line 1

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)

    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)

    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)

    at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)

    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1149)

    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1262)

    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)

    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)

    at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)

    at org.hibernate.loader.Loader.doQuery(Loader.java:662)

    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

    at org.hibernate.loader.Loader.doList(Loader.java:2144)

    ... 48 more

    问题补充:

    我的项目是用struts  hibernate 还有spring 组合的

    可是当我执行这个事务的时候 我的sql 语句无法执行

    public User findByEmail(String name , String password){

    String hql = "from com.buat.model.User";

    Query query =this.getSession().createSQLQuery(hql);

    List list = query.list(); //这里无法执行

    User user = list.get(0);

    return user ;

    }

    这是我的控制台所报的错误

    Hibernate: from com.buat.model.User

    2009-04-16 19:28:05,709 WARN [org.hibernate.util.JDBCExceptionReporter] -

    2009-04-16 19:28:05,712 ERROR [org.hibernate.util.JDBCExceptionReporter] -

    问题补充:

    你也没有给我解决的方案啊 、、、、

    2009年4月16日 19:23

    展开全文
  • LAMP下的PHP执行sql语句的写法:代码如下:@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器or die("数据库服务器连接失败");@mysql_select_db("test") //选择数据库mydbor ...
  • 从Professional Linux Programming中第5章有关MySQL的下列章节中,Neil Matthew和Richard Stones使用详尽的MySQL C接口向我们介绍了如何在MySQL数据库中执行SQL语句。他们将讨论返回数据的语句,例如INSERT以及不...
  • JDBC执行SQL语句: 一旦获得了链接,我们可以与数据库进行交互。JDBC Statement和PreparedStatement 接口定义了使 您能发送SQL命令并从数据库 进行接收数据的方法和属性。 1.Statement:创建语句对象 在使用...
  • php执行sql语句的写法php sql语句,后面都有详细的说明。最近的`php将会让你学到更多。就跟随百分网小编一起去了解下吧,想了解更多相关信息请持续关注我们应届毕业生考试网!复制代码 代码如下:@mysql_connect(...
  • c:\> mysqldump -h localhost -u root -p mydb mytable>e:\MySQL\mytable.sql 例 3:将数据库 mydb 的结构导出到 e:\MySQL\mydb_stru.sql 文件中。 c:\> mysqldump -h localhost -u root -p mydb --add-drop-table >...
  • 第一步:应用程序把查询SQL语句发给服务器端执行我们在数据层执行SQL语句时,应用程序会连接到相应的数据库服务器,把SQL语句发送给服务器处理。第二步:服务器解析请求的SQL语句SQL计划缓存,经常用查询分析器的...
  • 以上就是一条最简单的SQL更新语句,想要知道上面这句SQL语句怎么执行的先要了解MySQL数据库的逻辑架构。UPDATE语句也不例外的执行这个流程,先连接数据库(连接器),然后将SQL语句进行词法分析,并检测SQL语法...
  • 概览最近开始在学习mysql相关知识,自己根据学到的知识点,根据自己的理解整理分享出来,本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新是怎么完成的。...
  • 概览本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新是怎么完成的。一、mysql架构分析下面是mysql的一个简要架构图:mysql主要分为Server层和存储引擎层Server...
  • 概览本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新是怎么完成的。一、mysql架构分析下面是mysql的一个简要架构图:mysql主要分为Server层和存储引擎层Server...
  • 写在前面的话:有时不理解SQL语句各个部分执行顺序,导致理解上出现偏差,或者是书写SQL语句时随心所欲,所以有必要了解一下sql语句执行顺序。可以有时间自己写一个简单的数据库,理解会更加深入。下面写写我的...
  • 数据库服务接受查询sql,执行sql前判断要执行的sql是否是查询语句。0x02:查询缓存先行 MySQL在开启查询缓存的情况下,首先会先在查询缓存中查找该SQL是否完全匹配,如果完全匹配,验证当前用户是否具备查询权限,...
  • } } //返回sql语句结果条数 public function getNums($sql){ return mysql_num_rows($this->query($sql)); } //insert插入数据方法 public function insert($sql) { } //读取错误方法 public function get...
  • SELECT a.id,a.score_id,a.fname,a.age,a.school,b.verbal,b.math,b.english FROM users AS a LEFT JOIN score AS b ON a.score_id = b.score_id 转换 ![图片说明]...
  • 前言之所以要用maven来...怎么用使用maven执行sql语句需要依赖sql-maven-plugin这个插件,下面就直接从项目pom文件的配置入手进行简要介绍:buglife-data-accessorg.codehaus.mojosql-maven-plugin1.5mysqlmysql-co...
  • sql查询语句中字段有几十个,并且有大量的聚合函数,求最大最小值,...,表中数据量非常多,也建了索引,在PLsql 中执行sql语句,一直在执行,强行停止停止不下来, 怎么处理,sql语句怎么优化,数据库是不是有点问题啊
  • 展开全部因为SQL脚本中的Go是单独成行的636f70793231313335323631343130323136353331333337396236,所以比较好判断,另外脚本中最好不要含有注释语句,如果注释过长的话会换行,这样要多判断一次。另外SQL脚本要是...
  • <div><p>作者你好! 不知道有没有提供方法输出当前执行sql语句,方便日志调试。</p><p>该提问来源于开源项目:ali-sdk/ali-rds</p></div>
  • 用SESSION执行1.获取事务的session 2.用session执行 用插件实现public class JdbcUtil {static ComboPooledDataSource dataSource_ora;static ComboPooledDataSource dataSource_gp;static ComboPooledDataSource ...
  • Connection conn=null; Statement stmt=null; ResultSet rs=null; rs=stmt.executeQuery("select * from fund_profit_analsis where fund_name= "+fundname.trim()+"");
  • 本文就来总结一下Entity Framework中怎么写原生sql语句怎么通过sql语句来查询数据,修改数据。一、EF写原生的sql语句返回实体DbSet的SqlQuery方法可以传入原生的sql语句来返回实体,如果返回的实体对象是通过linq...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,142
精华内容 1,256
关键字:

怎么执行sql语句