javamysql变量,如何使⽤Java变量向mysql表插⼊值?Hi i am trying to insert the values in to mysql table. i am trying this code.
i have assigned values to variable and i want to pass that variable to that insert statement.
Is this correct?
code
int tspent = "1";
String pid = "trng";
String tid = "2.3.4";
String rid = "tup";
String des = " polish my shoes!";
INSERT INTO `time_entry`(pid,tid,rid,tspend,description) VALUE ('"+pid+"','"+tid+"','"+rid+"',"+tspent+",'"+des+"'); here is what i have tried, but i am not able to insert valu
es
try
{
conn=DBMgr.openConnection();
String sqlQuery = "INSERT INTO `time_entry`(pid,tid,rid,tspend,description) VALUE
('"+pid+"','"+tid+"','"+rid+"',"+tspent+",'"+des+"');";
st = ateStatement();
rs = st.executeQuery(sqlQuery);
}
解决⽅案
Try this,
String driver="sql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/dbname";
String uname="username";
mysql下载完如何使用String pass="password";
Class.forName(driver);
Connection c=(Connection) Connection(url,uname,pass);
Statement ateStatement();
('"+pid+"','"+tid+"','"+rid+"',"+tspent+",'"+des+"')");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论