• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Syntax error in INSERT INTO statement

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My table:
SlNo is an Integer and remaning all the feilds are Text. and Feild sizes are bigger then what is insert.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to copy the query and run in the the SQL prompt then it might gives you the proper eror.
reply
    Bookmark Topic Watch Topic
  • New Topic