Try converting the int into a string.
E.g.
> int pid1;
> pid1=din.readInt();
String pid1;
pid1 = Integer.toString(din.readInt());
I didn't test it, but this seems like the problem.
Troy
>
> Hello Everybody,
>
> I have written one program in java2 to write the data
> in postgresql. I am storing one integer and one string
> in the database. When i read the string from the file
> it is proper. But when i store it, it gives the
> following exception:
> java.sql.SQLException: ERROR: parser: parse error at
> or near ""
>
> I am not able to detect the error. Can any one run the
> code and correct the problem?
> When I assign the string test1 some fixed value and
> store it then the program works fine.
>
> Here is the code:
>
>
> //Import Various Classes
> import javax.swing.*;
> import javax.swing.border.*;
> import java.awt.*;
> import java.awt.event.*;
> import java.io.*;
> import java.util.*;
> import java.sql.*;
> import java.text.*;
>
> // THE CLASS DEFINITATION OF MAIN FRAME.
> class db1
> {
>
> Connection db;
> Statement st;
> //THIS IS THE MAIN METHOD
> public db1(String args[]) throws
> ClassNotFoundException,FileNotFoundException,IOException,SQLException
> {
> String url = args[0];
> String usr = args[1];
> String pwd = args[2];
>
> int pid1;
> String test1=null;
> Class.forName("postgresql.Driver");
>
> // Connect to database
> System.out.println("Connecting to Database URL = " +
> url);
> db = DriverManager.getConnection(url, usr, pwd);
>
> System.out.println("Connected...Now creating a
> statement");
> st = db.createStatement();
> st.executeUpdate("create table temp125(pid
> int4,filen char(200))");
>
> PreparedStatement ps = db.prepareStatement("insert
> into temp125 values (?,?)");
> try
> {
> FileInputStream fin=new FileInputStream("test1");
> DataInputStream din=new DataInputStream(fin);
> try
> {
> pid1=din.readInt();
> System.out.println(pid1);
> int len1=din.readByte();
> byte[] lent=new byte[len1+2];
> for(int i=0;i<=len1+1;i++)
> {
> lent[i]=din.readByte();
> }
> test1=new String(lent);
> System.out.println(test1);
> ps.setInt(1,pid1);
> ps.setString(2,test1);
> try{
> int x=ps.executeUpdate();
> }
> catch (SQLException ex){
> System.out.println("Exception="+ex);
> }
>
>
>
> }
> catch(IOException e1)
> {
> System.out.println("IO");
> }
>
> }
> catch(FileNotFoundException e)
> {
> System.out.println("File not found");
> }
> ps.close();
>
>
> System.out.println("Now closing the connection");
> st.close();
> db.close();
>
> }
>
> public static void main(String[] args)
> {
> try {
> db1 temp = new db1(args);
> } catch(Exception ex) {
> System.err.println("Exception caught.\n"+ex);
> ex.printStackTrace();
> }
> }
> }
>
> *************************************************
> The file which i read is test1 which is something
> like:
>
> wyt7GIsstustututuC4??
>
> Please run the code on your computer and let me know
> the problem.
>
> Thanking You
>
>
> =====
> KOTHARI ALPESH D.
> STUDENT M. TECH.
> CEDT
> INDIAN INSTITUTE OF SCIENCE
> BANGALORE-560 012
> INDIA
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com
>
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>
>
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]