473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I pass a string parameter stored in the variable to the sql statement?

108 100+
How do I insert a string that is stored in a variable into an sql statement?
Expand|Select|Wrap|Line Numbers
  1.  
  2. void InsertVehicle(double vehicle_locX,double vehicle_locY,int vehicle_TAID,double vehicle_Gpsid,double vehicle_speed,String vehicle_type,int vehicle_routeid,String vehicle_status,int vehicle_passengerno,int vehicle_capacity) throws SQLException{
  3.                     PreparedStatement preparedstatement=null;
  4.                     ResultSet resultset=null;
  5.                     String route_table;
  6.  
  7.                     if (conn!=null){
  8.  
  9.                             String sql="Insert into tbl_vehicle(vehicle_locX,vehicle_locY,vehicle_TAID,vehicle_Gpsid,vehicle_speed,vehicle_type,vehicle_routeid,vehicle_status,vehicle_passengerno,vehicle_capacity) Values("+vehicle_locX+","+vehicle_locY+","+vehicle_TAID+","+vehicle_Gpsid+","+vehicle_speed+","+'vehicle_type'+","+vehicle_routeid+","+vehicle_status+","+vehicle_passengerno+","+vehicle_capacity+")";
  10.                             preparedstatement=conn.prepareStatement(sql);
  11.                             preparedstatement.executeQuery();
  12.  
  13.                            }
  14.                     }
  15.  
Here I have vehicle_type which is of type string and while inserting it in my table 'vehicle_type' is stored instead of the value it contains.How do I sort this out?
Feb 17 '11 #1
0 1370

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark Horton | last post by:
I thought would be a super simple project, but I was wrong. I need Help!!!! I am using the Word.Application.Mailmerge.OpenDataSource to try and send a Dynamic Query to my stated Document.Open...
3
by: Alex Munk | last post by:
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert the string back into a 2-dimensional array....
2
by: SwatSoftwareDev | last post by:
Hi All, I want to use XML technologies with SQL Server 2000 for sending master details data from Application to SQL Server. I'm using xmldocument class for writing data in the form of attribute...
9
by: Martoon | last post by:
I want to instantiate an STL map with my own compare function, and I want to pass a parameter to the compare function that will be stored and used for all comparisons in that map instance. As an...
2
by: bbsbob | last post by:
Hello, I'm still using the Framework v1.1. Forgive me, I'm working on a legacy application. I'm using 2 iFrame sections with 2 aspx pages, i.e. 1.aspx (left) and 2.aspx (right) In 1.appx page,...
5
by: cpnet | last post by:
I'm able to pass string parameters with no problems to a LocalReport being displayed by the ASP.NET ReportViewer control. However, my report also has a DateTime parameter. ...
3
by: John Dalberg | last post by:
I have seen examples for List<T>.FindAll(findthis)where findthis is a predicate. How do I pass a parameter to this predicate so that I have different values to search for? I don't want to use...
5
by: raghutumma | last post by:
Hi, I am trying to Pass Column Name(FieldName) using Parameter in SQL Statement... But i am getting error... how can i pass Column name using parameter??? Example: in table i have...
14
by: bill | last post by:
Can someone please show me an example of passing a string value into an sql statement in vb 2005? Something like this is what I'm after: Dim sqlButton1 As String = "Select * from tblAssets where...
1
by: gpsharma | last post by:
Hi, I need to pass a parameter into a stored procedure which values are dynamic always. Executing a variable which having the Select statement. Following query working fine. BEGIN DECLARE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.