Home > Database > Mysql Tutorial > mysql-jdbc往Mysql中添加数据没反应,求教

mysql-jdbc往Mysql中添加数据没反应,求教

WBOY
Release: 2016-06-06 09:34:29
Original
1680 people have browsed it

mysqljavajdbc

jar包加了的哈,数据库Connection连接也没写错,运行起来代码也没有报错,代码如下

<code>@Testpublic void ZengTest()  {    Connection conn = null;    Statement sta = null;    try{        Class.forName("com.mysql.jdbc.Driver");        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/d-7test", "root", "cailikun");        sta = conn.createStatement();        //增加数据的sql:        String sql = "insert into `uesr`(name) values('小蔡') ";        sta.executeUpdate(sql);    }    catch(Exception e){        e.printStackTrace();        }finally{ //最后执行两次“事”            try{if(sta!=null){                sta.close();                }            }catch(Exception e){                e.printStackTrace();                    }finally{                try{if(conn!=null){                    conn.close();                    }                       }catch(Exception e){                    e.printStackTrace();                }            }        }}</code>
Copy after login

运行起来表格里什么都没有
图片说明

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template