I have figured it out the above problem...
but now i am having one more problem of :---
java.sql.SQLException: ORA-01722: invalid number at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.
I am trying to insert record into oracle database by reading it from notepad(textfile).. so i am having two table.... Photo and Restaurant....
For photo it gets inserted easily with no problem.... but for restaurant it is giving this error as soon as it start reading the first value of first row in my notepad..
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
public class populate {
public static void main(
String[] args)
throws java.lang.InterruptedException {
String driverClass = "oracle.jdbc.driver.OracleDriver";
String connectionURL = "jdbc:oracle:thin:@RJ:1521:ORCL";
String userID = "scott";
String userPassword = "tiger";
//String inputFileName = "photos.txt";
// String TABLE_TYPE = "PHOTO_TYPE";
String TABLE_NAME1 = "PHOTO";
String TABLE_NAME2 = "RESTAURANT";
String DELIM = ",";
Connection con = null;
String inputFileName1 = args[0];
String inputFileName2 = args[1];
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
Statement stmt1 = null;
Statement stmt2 = null;
int insertResults = 0;
StringTokenizer st1= null;
StringTokenizer st2= null;
String ID;
String NAME;
String X;
String Y;
String TAGS;
String ID_RESTAURANT;
String Name_RESTAURANT;
String X_RESTAURANT;
String Y_RESTAURANT;
String FOODTYPE;
String PHONENO;
try {
System.out.print(" Creating Statement...\n");
stmt1 = con.createStatement ();
stmt1.executeUpdate("delete from PHOTO");
stmt1.executeUpdate("commit");
System.out.print(" Create FileReader Object for file: " + inputFileName1 + "...\n");
FileReader inputFileReader1 = new FileReader(inputFileName1);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream1 = new BufferedReader(inputFileReader1);
String inLine1 = null;
while ((inLine1 = inputStream1.readLine()) != null) {
st1 = new StringTokenizer(inLine1, DELIM);
ID = st1.nextToken();
NAME = st1.nextToken();
X = st1.nextToken();
Y = st1.nextToken();
TAGS = st1.nextToken();
System.out.print(" Inserting value for [" + NAME + "]\n");
insertResults = stmt1.executeUpdate(
"INSERT INTO " + TABLE_NAME1 + " VALUES ("
+ ID +
" , '" + NAME + "'" +
" , '" + X + "'" +
" , '" + Y + "'" +
" , '" + TAGS + "')");
System.out.print(" " + insertResults + " row created.\n");
System.out.print(" " + ID + " FOR PARTICLUAR ROW.\n");
System.out.print(" " + NAME + " row created.\n");
System.out.print(" " + X + " row created.\n");
System.out.print(" " + Y + " row created.\n");
}
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream1.close();
System.out.print(" Closing Statement...\n");
stmt1.close();
------- till this data is getting inserted in to my PHOTO table.... but after this for RESTAURANT table it displayS the error of invalid number..... as i have posted above
// for restaurant
System.out.println();System.out.println();System.out.println();
System.out.print(" Creating Statement for restaurants...\n");
stmt2 = con.createStatement ();
stmt2.executeUpdate("delete from RESTAURANT");
stmt2.executeUpdate("commit");
System.out.print(" Create FileReader Object for file: " + inputFileName2 + "...\n");
FileReader inputFileReader2 = new FileReader(inputFileName2);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream2 = new BufferedReader(inputFileReader2);
String inLine2 = null;
while ((inLine2 = inputStream2.readLine()) != null) {
st2 = new StringTokenizer(inLine2, DELIM);
ID_RESTAURANT = st2.nextToken();
Name_RESTAURANT = st2.nextToken();
X_RESTAURANT = st2.nextToken();
Y_RESTAURANT = st2.nextToken();
FOODTYPE = st2.nextToken();
PHONENO = st2.nextToken();
System.out.print(" Inserting value for [" + Name_RESTAURANT + "]\n");
insertResults = stmt2.executeUpdate(
"INSERT INTO " + TABLE_NAME2 + " VALUES ("
+ ID_RESTAURANT +
" , '" + Name_RESTAURANT + "'" +
" , '" + X_RESTAURANT + "'" +
" , '" + Y_RESTAURANT + "'" +
" , '" + FOODTYPE + "'" +
" , '" + PHONENO+ "')");
System.out.print(" " + insertResults + " row created.\n");
}
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream2.close();
System.out.print(" Closing Statement...\n");
stmt2.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
----------------------------------------------------------------------
do reply what is the problem.... as in my database these are the tabe that i am using....
CREATE TABLE PHOTO(
ID NUMBER NOT NULL PRIMARY KEY ,
Name VARCHAR2(10),
X DOUBLE PRECISION,
Y DOUBLE PRECISION,
Tags VARCHAR2(40)
);
CREATE TABLE RESTAURANT(
ID_RESTAURANT NUMBER NOT NULL PRIMARY KEY ,
Name_RESTAURANT VARCHAR2(10),
X_RESTAURANT DOUBLE PRECISION,
Y_RESTAURANT DOUBLE PRECISION,
FOODTYPE VARCHAR2(20),
PHONENO NUMBER
);