JDBC problem with string

Поиск
Список
Период
Сортировка
От ALPESH KOTHARI
Тема JDBC problem with string
Дата
Msg-id 19990930012847.7357.rocketmail@web601.yahoomail.com
обсуждение исходный текст
Список pgsql-interfaces
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 want to 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 (say
"foo") and run the code, 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
temp(pid
int4,filen char(200))");                              PreparedStatement ps =
db.prepareStatement("insert
into temp 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;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(FileNotFoundExceptione)               {                       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(Exceptionex) {                     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


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Spirou
Дата:
Сообщение: Re: [INTERFACES] psql trerminal behaviour
Следующее
От: "Tim Joyce"
Дата:
Сообщение: Re: [INTERFACES] psql trerminal behaviour