From: ALPESH KOTHARI <alpeshkothari@yahoo.com>
To: pgsql-interfaces@postgresql.org
Subject: JDBC problem with string
Date: Wed, 29 Sep 1999 18:28:47 -0700 (PDT)
Message-ID: <19990930012847.7357.rocketmail@web601.yahoomail.com> (raw)
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(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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: alpeshkothari@yahoo.com
Subject: Re: JDBC problem with string
In-Reply-To: <19990930012847.7357.rocketmail@web601.yahoomail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox