Karan Raj

Greenhorn
+ Follow
since Jan 27, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Karan Raj

hi,

is there any method through which i can depict multiple selections in the JTextArea....?

thanks
karan
17 years ago
Hi,

i tried to run the program with following sample code.but i am not able to pass command line inputs.

sample code:
---------------------------
public static void main(String args[]){

Runtime rr=Runtime.getRuntime();
try{

Process p=rr.exec("primer");BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));

BufferedWriter or = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
String l=new String();


while((l=br.readLine())!=null){


System.out.println(">>>"+l);


try{

or.write(4);
or.write('\n');
or.write('\r');

or.flush();

}catch(Exception e){
System.out.println("exception"+e);
}

}
System.out.flush();

}catch(Exception ioe){
System.out.println("Exception is:"+ioe);
}


}

}
---------------------------------
if i run the above sample code i am not able to see anything until i terminate the program.

please help me in this..if you have any sample code..that will help me in understanding how to do processing.

thanks in advance
karan
17 years ago
Hi,

As part of my application i have to interact with other program..whose source code is not available to me. I am trying to excute that program using "Runtime" class.

name of the other program is rimer
-----------------------------------------------
#$primer -c
#$primer program running...
#$Enter the temp : 30
#$wrong entry...temp should be between 40-70.reenter
#$Enter the temp : 45
#$Enter the wordlength:20

----------------------------------------------
above is a sample program i have. i have to integrate it with my java application. i am able to run the program using "Runtime"..but how can i send the arguments & how can i handle error situations..?

please help me in this

thanks in advance
karan
17 years ago
Hi,

can anyone tell me...how to interact with other programs(written in perl) using java. my java application should integrate with other program and it should interact with other program in providing input and it should take the output from it for further processing.

Thanks in advance
karan
17 years ago
Hi,
i am getting the following exception when i try to connect to mysql from my program.
i am trying to connect with the following program statement
>>sql=DriverManager.getConnection("jdbc:mysql://Bithorax/mysql?user=samurai&password=helloworld");
The user samurai already exists in the database;
exception:
------------------------------------------------------------------
java.sql.SQLException: General error, message from server: "Access denied for user: 'samurai@bithorax' to database 'mysql'"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1803)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:887)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1627)
at com.mysql.jdbc.Connection.<init>(Connection.java:427)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:395)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
----------------------------------------------------------
i am unable to traceout the problem please help in this.
Thanks
karan
Hi Vanda,
Thanks for your help. your solution is very clear
Karan
17 years ago
hi,
Thanks for ur help.
vijay u r code is working fine..but i am not getting the column names for that table.
i am just learning jtables .I am not getting column names when i try to create a table with vectors.since a week i am trying this.
Can anyone explain what are specific things i need to take care while creating a table.

--karan
17 years ago
hi,
I am getting the following exception with my program.please chek this once.
------------------------------------------------------------
Exception in thread "main" java.lang.ClassCastException
at javax.swing.table.DefaultTableModel.justifyRows DefaultTableModel.jav
a:238)
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
ava:194)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:131
)
at guidemo.<init>(guidemo.java:37)
at guidemo.main(guidemo.java:60)
----------------------------------------------------------------
i am tried to create a table with vectors.my code is as follows
code:-
-----
class guidemo extends JFrame{
private JTable data_tab;
private JLabel ptitle;
private Container c;
private Vector vdata;
private Vector vcolname;

public guidemo(){
super("EST Project Demo");
DefaultTableModel dtm;
c=getContentPane();
c.setLayout(null);
c.setSize(300,200);//intialising the contentpane

ptitle=new JLabel("EST project Details");
ptitle.setBounds(60,30,150,40);
c.add(ptitle);
setTableData();//intialising the vectors with some data
dtm=new DefaultTableModel(vdata,vcolname);
data_tab=new JTable(dtm);//setting table model
//data_tab.setPreferredScrollableViewportSize(new Dimension(500, 100));
c.add(data_tab);

WindowListener wndCloser = new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
}

public static void main(String[] args)
{
System.out.println("Hello World!");
setDefaultLookAndFeelDecorated(true);
new guidemo();
}

public void setTableData(){//intialise vectors with some data
vdata=new Vector();
vcolname=new Vector();
vdata.removeAllElements();
vdata.addElement(new dat("Eliuh",90,900,"uy89"));
vdata.addElement(new dat("Eryuh",920,900,"uy89"));
vdata.addElement(new dat("Elddh",940,900,"uy89"));
vdata.addElement(new dat("Elideu",90,900,"uy89"));
vdata.addElement(new dat("Elwciuh",760,900,"uy89"));
vdata.addElement(new dat("Elhhiuh",90,900,"uy89"));
vdata.addElement(new dat("Elicuh",100,900,"uy89"));
vdata.addElement(new dat("Eliuech",90,900,"uy89"));
vcolname.addElement(new cname("NAME","QStart","Qend","PID"));
}
}

class dat{
String name,gid;
int val,val2;
public dat(String n,int v,int v1,String g){
name=n;
val=v;
val2=v1;
gid=g;
}
}
class cname{
String s1,s2,s3,s4;
cname(String q, String w, String t, String y){
s1=q;
s2=w;
s3=t;
s4=y;
}
}
----------------------------------------------------------
I am not able to understand why i am getting that exception.if any body have solution for my problem it will be greatly helpful for me.
thanks,
karan
17 years ago
hi,
I am getting the following exception with my program.please chek this once.
Exception in thread "main" java.lang.ClassCastException
at javax.swing.table.DefaultTableModel.justifyRows DefaultTableModel.jav
a:238)
at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.j
ava:194)
at javax.swing.table.DefaultTableModel.<init>(DefaultTableModel.java:131
)
at guidemo.<init>(guidemo.java:37)
at guidemo.main(guidemo.java:60)
----------------------------------------------------------------
i am tried to create a table with vectors.my code is as follows
code:-
-----
class guidemo extends JFrame{
private JTable data_tab;
private JLabel ptitle;
private Container c;
private Vector vdata;
private Vector vcolname;

public guidemo(){
super("EST Project Demo");
DefaultTableModel dtm;

c=getContentPane();
c.setLayout(null);
c.setSize(300,200);//intialising the contentpane



ptitle=new JLabel("EST project Details");

ptitle.setBounds(60,30,150,40);

c.add(ptitle);
setTableData();//intialising the vectors with some data

dtm=new DefaultTableModel(vdata,vcolname);
data_tab=new JTable(dtm);//setting table model
//data_tab.setPreferredScrollableViewportSize(new Dimension(500, 100));
c.add(data_tab);

WindowListener wndCloser = new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};

addWindowListener(wndCloser);
setVisible(true);

}

public static void main(String[] args)
{
System.out.println("Hello World!");
setDefaultLookAndFeelDecorated(true);
new guidemo();
}

public void setTableData(){//intialise vectors with some data
vdata=new Vector();
vcolname=new Vector();
vdata.removeAllElements();
vdata.addElement(new dat("Eliuh",90,900,"uy89"));
vdata.addElement(new dat("Eryuh",920,900,"uy89"));
vdata.addElement(new dat("Elddh",940,900,"uy89"));
vdata.addElement(new dat("Elideu",90,900,"uy89"));
vdata.addElement(new dat("Elwciuh",760,900,"uy89"));
vdata.addElement(new dat("Elhhiuh",90,900,"uy89"));
vdata.addElement(new dat("Elicuh",100,900,"uy89"));
vdata.addElement(new dat("Eliuech",90,900,"uy89"));
vcolname.addElement(new cname("NAME","QStart","Qend","PID"));
}

}

class dat{
String name,gid;
int val,val2;
public dat(String n,int v,int v1,String g){
name=n;
val=v;
val2=v1;
gid=g;

}
}
class cname{
String s1,s2,s3,s4;
cname(String q, String w, String t, String y){
s1=q;
s2=w;
s3=t;
s4=y;
}
}
----------------------------------------------------------
I am not able to understand why i am getting that exception.if any body have solution for my problem it will be greatly helpful for me.
thanks,
karan
I already gave all privileges to user 'samurai'..
mysql> GRANT ALL PRIVILEGES ON SST.* TO 'samurai' IDENTIFIED BY 'helloworld';
i am able to access all tables in SST with samurai user manually. but i am getting error when i tried with my java code.I am not able to understand why it is giving ".... 'HOST '@localhost is not allowed to connect to MySql".
I tried the code even on the server system but it's giving same kind of error.
Hi,
As a part of project i wrote the code to connect to mysql using java.In my system it is working fine.but when i tried on the server(even as root also) i am getting an error message.I am not able to sort out the what the problem could be..?
mycode is
{
...................................
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (Exception E) {
System.err.println("CONCEPT: Unable to Load Driver ");
E.printStackTrace();
}
try {
System.out.println("Connecting...");
Connection c = DriverManager.getConnection(
"jdbc:mysql://localhost/mysql?user=samurai&password=helloworld");
System.out.println("Connection ok: " + c);
System.out.println("Creating BankID table:");
Statement stmt=c.createStatement();
stmt.executeUpdate("use SST");
stmt.executeUpdate("CREATE TABLE BANKID (EID VARCHAR(20) UNIQUE)");
System.out.println("Table with following Attributes is created:");
ResultSet res=stmt.executeQuery("DESCRIBE BANKID");
while(res.next()){
String s=res.getString("Field");
System.out.println("-->"+s);
s=res.getString("Type");
System.out.println("-->"+s);
}
}catch (SQLException E) {
System.out.println ("SQLException: " + E.getMessage());
System.out.println ("SQLState: " + E.getSQLState());
System.out.println ("VendorError: " + E.getErrorCode());
}
}
public void addGID(String name){

String Query;
Query="INSERT INTO TABLE BANKID VALUES ( "+name +" )";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (Exception E) {
System.err.println("CONCEPT: Unable to Load Driver ");
E.printStackTrace();
}..................
..............................

The above code is working fine in mysystem.but it's giving the following error when i try to run it on other system.
Error Message:
SQL Error: Data Source rejected for the establishment of the connection.user 'Host'@localhost is not allowed to connect to MySql Server.

Vendor Error Code: 1130

please help me

Thanks,
karan
Hi,

i wanna develope applications, by which i can connect to databases and excute queries.Can anybody suggest me..the best way so that i can start developing applications quickly using JDBC...i am new to java...please help me.

thanks,
karan
hi,
Can anybody tell me ..how can i display data in table if it has subheadings in it. For example

//--------------------customar.dat--------------
ID Name ph.no
Florida(45/6,Thomasvile-09)

231 Sam 55398444
534 Hone 55346674
Texas(332/3 ,Downtown-22)
122 Raseen 23454464
544 Plank 45223665
Indiana(44/2, Indianapolis-88)
53 ush 65322423
22 villy 65364546

//-----------------------------------

I have the above output file. i have to convert it to table format.
i able to generate the table ...but don't know how to put subheadings in it.please help me in this.
thanks,
Karan
17 years ago
Thanks jhonson, your solution is simple and easy
17 years ago
Hi David,

thanks for your inputs.My actual problem is....I don't know the length of the data i want to store. For my purpose i used Vectors for storing.This is the sample code i used for it.
Vector v=new Vector(2,3);
Object temp[]={"ADD332343",new Integer(230),new Double(3.22),
new Integer(22)}

v.addElement(temp);

Object t;
t=v.elementAt(0);

but how i can i refer to the individual elements in the "t"...? .
please help me...i am just learning java
Thanks
Karan
17 years ago