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 ]