我的SQL JDBC代码中的错误 [英] error in my sql jdbc code

查看:78
本文介绍了我的SQL JDBC代码中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的sql jdbc代码有问题.代码中有错误,我不知道错误
代码如下

I have problem in my sql jdbc code .there is errorin code , I do not know the error
code is the following

try{String c;
   String w= area.getText();
     Class.forName("com.mysql.jdbc.Driver");
    Connection mycon=null;
       
     mycon=DriverManager.getConnection("jdbc:mysql://localhost:90/phpmyadmin/");
               Statement statement=mycon.createStatement();
              // JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE); 
               ResultSet rst=statement.executeQuery("insert into d.t "+ "values(1,'c',w )");
  
    
    
    
    
    }
catch(SQLException exp) 
{      }
catch(ClassNotFoundException e)
{}

查询不起作用,数据库的数据未更改

the query does not work and the data of my database is not changed

推荐答案

您没有传递w的值.
这是传递给数据库的sql:
插入d.t values(1,''c'',w)

将代码更改为
ResultSet rst = statement.executeQuery(插入d.t" +"values(1,''c"," + w +'')");

希望这会有所帮助.
You are not passing the value of w.
This is the sql being passed to the database:
insert into d.t values(1,''c'',w )

Change the code to
ResultSet rst=statement.executeQuery("insert into d.t "+ "values(1,''c'', ''" + w + "'')");

Hope this helps.


这篇关于我的SQL JDBC代码中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆