aspose file tools*
The moose likes JDBC and the fly likes Syntax error in INSERT INTO statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Syntax error in INSERT INTO statement" Watch "Syntax error in INSERT INTO statement" New topic
Author

Syntax error in INSERT INTO statement

varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
Hi,
I am new and i get SQLException. Please help me.
Here is my code & Exception
/********************************************************/
Exception :
E:\StreamDetails\program>java StreamDetails
InsertStr :
INSERT INTO StreamDetails1 (SlNo,Name,Codec,Level,Duration,VideoBitRate,VideoAspectRatio,FrameRate,AudioStandard,AudioBi
tRate,SamplingFreq,AudioDuration) VALUES (1,'Mask_av4570kbps_v4450kbps_NTSC_720x480_a120kbps_48khz_AAC_stereo.ProgDwnl.m
p4','MPEG-4 Simple ',' L3',' 248.541 secs',' 4457 kbps',' 720x480 ',' 24.000064 fps','MPEG-4 AAC LC',' 120 kbps',' 48000
Hz',' 248.533 secs')
SQLException : [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
at StreamDetails.main(StreamDetails.java:139)

E:\StreamDetails\program>



Code :
import java.sql.*;
import java.io.*;
import java.util.*;

public class StreamDetails {
public static void main(String args[])
{
String url = "jdbc dbc:STREAMS"; //"student is data source name"
Connection connect;
String createTableString;
Statement stmt;


String filename;
String codec;
String level;
String Duration;
String BitRate;
String AspectRatio;
String FrameRate;

String audioStandard;
String audiobitrate;
String samplingFreq;
String audioDuration;

/****************************************************/
/*JDBC ODBC CONNECTION*/
/****************************************************/

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try
{
InputFile in = new InputFile("E:\\StreamDetails\\Parsing\\OutPutFile.txt");
String s;
int i = 1;
connect = DriverManager.getConnection(url, "", "");
stmt = connect.createStatement();
StringTokenizer st ;
int StrInd=1;

while((s = in.getLine()) != null)
{
st = new StringTokenizer(s, ",");
StrInd=1;
while (st.hasMoreTokens())
{
filename =new String(st.nextToken());
codec = new String(st.nextToken());
level = new String(st.nextToken());
Duration = new String(st.nextToken());
BitRate = new String(st.nextToken());
AspectRatio = new String(st.nextToken());
FrameRate = new String(st.nextToken());
audioStandard = new String(st.nextToken());
audiobitrate = new String(st.nextToken());
samplingFreq= new String(st.nextToken());
audioDuration = new String(st.nextToken());
String InsertStr = "INSERT INTO StreamDetails1 (SlNo,Name,Codec,Level,Duration,VideoBitRate,VideoAspectRatio,FrameRate,AudioStandard,AudioBitRate,SamplingFreq,AudioDuration) VALUES ("+StrInd+",'"+filename+"','"+codec+"','"+level+"','"+Duration+"','"+BitRate+"','"+AspectRatio+"','"+FrameRate+"','"+audioStandard+"','"+audiobitrate+"','"+samplingFreq+"','"+audioDuration+"')";
System.out.println("InsertStr "+ ": \n" + InsertStr);
stmt.executeUpdate(InsertStr);

System.out.println("Insert Statement completed ");
StrInd++;
break;

}



}
in.cleanup();
stmt.close();
connect.close();

}
catch(SQLException ex)
{
System.err.println("SQLException : " + ex.getMessage());
ex.printStackTrace(System.err);
}
catch(Exception e) {
System.err.println("Caught in main, e.printStackTrace():\n");
e.printStackTrace(System.err);
}

}

}

/********************************************************/
/*READ THE INPUT FILE CLASS*/
/********************************************************/

class InputFile {
private BufferedReader in;
InputFile(String fname) throws Exception {
try {
in =
new BufferedReader(
new FileReader(fname));
// Other code that might throw exceptions
} catch(FileNotFoundException e) {
System.err.println(
"Could not open " + fname);
// Wasn't open, so don't close it
throw e;
} catch(Exception e) {
// All other exceptions must close it
try {
in.close();
} catch(IOException e2) {
System.err.println(
"in.close() unsuccessful");
}
throw e; // Rethrow
} finally {
// Don't close it here!!!
}
}
String getLine() {
String s;
try {
s = in.readLine();
} catch(IOException e) {
System.err.println(
"readLine() unsuccessful");
s = "failed";
}
return s;
}
void cleanup() {
try {
in.close();
} catch(IOException e2) {
System.err.println(
"in.close() unsuccessful");
}
}
}
/*********************************************************/
[ August 04, 2005: Message edited by: Bear Bibeault ]
praveen kanakarajan
Ranch Hand

Joined: Apr 27, 2005
Posts: 54
are you sure you are not trying to insert values greater than the column size specified.its just a suggestion.it will be helpful if you can give the table details
varkala prabhakar
Ranch Hand

Joined: Sep 08, 2001
Posts: 54
My table:
SlNo is an Integer and remaning all the feilds are Text. and Feild sizes are bigger then what is insert.
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
Try to copy the query and run in the the SQL prompt then it might gives you the proper eror.
 
Don't get me started about those stupid light bulbs.
 
subject: Syntax error in INSERT INTO statement