本文介绍了我如何从文本字段中获取用户输入,将字符串传递给sql查询......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是新手,我无法解决问题。我的代码是: .......hi i am new in this and i can not solve the problem.my code is:.......public void actionPerformed(ActionEvent e) {String nid = new String(t1.getText());String name = new String(t2.getText());String phn_no = new String(t3.getText());String email = new String(t4.getText());String address = new String(t5.getText());String room_no = new String(t6.getText());String iss_date = new String(t7.getText());String res_days = new String(t8.getText());String bill_paid = new String(t9.getText());String due = new String(t10.getText());if (e.getSource() == e1) {try{//INSERTING DATA TO CUSTOMER TABLE//step1 load the driver classClass.forName("oracle.jdbc.driver.OracleDriver");//step2 create the connection objectConnection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","almaksud");//step3 create the statement objectStatement stmt=conn.createStatement();//step4 execute queryResultSet rs=stmt.executeQuery("INSERT INTO CUSTOMER VALUES("+nid+","+name+","+phn_no+","+email+","+address+","+room_no+","+iss_date+","+res_days+","+bill_paid+","+due+ ")");while(rs.next())//step5 close the connection objectconn.close();}catch(Exception d){ System.out.println(e);} ................ .................. ..................... 其实我要做的是我创造了一个有10个框架textfiedl从t1到t2,两个按钮保存并退出。 .............................................................actually what i am trying to do is that i have created a frame which have 10 textfiedl they are from t1 to t2 and two button "save and exit".......String nid = new String(t1.getText()); String name = new String(t2.getText()); String phn_no = new String(t3.getText()); String email = new String(t4.getText()); String address = new String(t5.getText()); String room_no = new String(t6.getText()); String iss_date = new String(t7.getText()); String res_days = new String(t8.getText()); String bill_paid = new String(t9.getText()); String due = new String(t10.getText()); ............... ...这部分将从文本字段中获取字符串值并将它们传递给sql查询..................this part will take string value from text field and pass them to the sql queryResultSet rs=stmt.executeQuery("INSERT INTO CUSTOMER VALUES("+nid+","+name+","+phn_no+","+email+","+address+","+room_no+","+iss_date+","+res_days+","+bill_paid+","+due+ ")"); 如果我点击保存按钮然后执行查询,那么每个字符串都会被保存在database.please帮助我.......if i click the button "save" and then the query will be executed and so every string will be saved in database.please help me.......推荐答案 这篇关于我如何从文本字段中获取用户输入,将字符串传递给sql查询......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 11:18
查看更多