pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedJDBC problem with string
2+ messages / 2 participants
[nested] [flat]
* JDBC problem with string
@ 1999-09-30 01:28 ALPESH KOTHARI <alpeshkothari@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: ALPESH KOTHARI @ 1999-09-30 01:28 UTC (permalink / raw)
To: 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(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
^ permalink raw reply [nested|flat] 2+ messages in thread
* RE: [INTERFACES] JDBC problem with string
@ 1999-09-30 08:02 Peter Mount <petermount@it.maidstone.gov.uk>
0 siblings, 0 replies; 2+ messages in thread
From: Peter Mount @ 1999-09-30 08:02 UTC (permalink / raw)
To: 'ALPESH KOTHARI' <alpeshkothari@yahoo.com>; pgsql-interfaces; +Cc: Peter Mount (Home) <peter@retep.org.uk>
What version of the driver are you using?
The Exception you noted usually means that you missed out setting a
value to one or more parameters, but you haven't missed any in your
code.
I'll check this out when I get back home. I'm not aware of any problems
with PreparedStatement.
Peter
--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council.
-----Original Message-----
From: ALPESH KOTHARI [mailto:alpeshkothari@yahoo.com]
Sent: 30 September 1999 02:29
To: pgsql-interfaces@postgreSQL.org
Subject: [INTERFACES] JDBC problem with string
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:
*************************************************
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-09-30 08:02 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-09-30 01:28 JDBC problem with string ALPESH KOTHARI <alpeshkothari@yahoo.com>
1999-09-30 08:02 RE: [INTERFACES] JDBC problem with string Peter Mount <petermount@it.maidstone.gov.uk>
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