mayank yadav

Greenhorn
+ Follow
since Sep 25, 2005
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 mayank yadav

well rajesh you have many options
1. you can use the java.io package
2. by inserting the value in a variable

1. you can refer any tutorials
2.
in this method
if tf is a text box where you are entring your value then
declare a string say String temp:
while actionperforming ....if e is event of clicking a button
then
if(e.getSource == b)

{
temp=tf.getSource();
// now your value is in the String temp
try
{
*********jdbc conxs********
stmt.executeUpdate("INSERT INTO PHONEDIARY(COLOUMN NAME)
VALUES('"temp"');
}
}




dont forget to write your sql connection commands..
i think this will solve your problem
hi....in the given codes
after compiling iam getting an error
data types not matching.....
please help me to correct it...

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button.*;

public class List extends JFrame
{
public String s;
JFrame f;
JPanel po;
JComboBox cb;
JTextField tf;


public static void main (String arg[])
{

List obj = new List();
}


public List()
{


f = new JFrame("list");
po= new JPanel();
tf= new JTextField(30);
f.getContentPane().add(po);
f.setVisible(true);
f.setSize(300,300);
String[] hos = {"Hostel1","Hostel2","Hostel3","hostel4","hostel6"};
cb = new JComboBox(hos);
cb.setMaximumRowCount(3);
//cb.addItemListener(this);
po.add(cb);
po.add(tf);
process();



}

public void process()
{
s= hos[cb.getSelectedItem()];
tf.setText(s);

}
}
13 years ago
hi....in the given codes
after compiling iam getting an error
VARIABLE hos not found.....
please help me to correct it...

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button.*;

public class List extends JFrame
{
public String s;
JFrame f;
JPanel po;
JComboBox cb;
JTextField tf;


public static void main (String arg[])
{

List obj = new List();
}


public List()
{


f = new JFrame("list");
po= new JPanel();
tf= new JTextField(30);
f.getContentPane().add(po);
f.setVisible(true);
f.setSize(300,300);
String[] hos = {"Hostel1","Hostel2","Hostel3","hostel4","hostel6"};
cb = new JComboBox(hos);
cb.setMaximumRowCount(3);
//cb.addItemListener(this);
po.add(cb);
po.add(tf);
process();



}

public void process()
{
s= hos[cb.getSelectedIndex()];
tf.setText(s);

}
}
13 years ago
i have now tried this
program using buffer reader
where the input is saved in the string ss
and then passed to the sql statement...
but iam gettin an exception ..saying too few parameters..
please help me...iam struck with this for a long time...


import java.io.*;
import java.sql.*;



class buffer1
{
public static void main(String ar[])
throws IOException
{



BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );

String line1;
// declaration of input Strings
int first;
// declaration of int variables

System.out.println("Enter first Name:");
line1 = stdin.readLine();
//first = Integer.parseInt( line1 ); // convert line1 to first int
System.out.println("The name is " +line1);



try {

// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc dbc:mayank";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();



//these two statements does not execute durin the program

int m;

//String k= "line1";
m= st.executeUpdate("insert into mayank(class) values(line1) ");

ResultSet rs;

rs= st.executeQuery("select class,name from mayank ");


conn.commit();

while(rs.next())

{
String n= rs.getString("name");
String c = rs.getString("class");
System.out.println(n + " " + c);
}


}

catch (Exception e)

{
e.printStackTrace();
/*System.err.println("Got an exception! ");
System.err.println(e.getMessage());
*/
}

}






}
hii..thnks for ur advice
this time i have used java.io for
enterin values
but again the program is compiling but
values r not entered..plzz help


import java.io.*;
import java.sql.*;


public class buffer

{

public static void main(String [] args)

{
//try{
String ss;
while(true)
{
ss = getLine();
ss = ss.trim();
if (ss.charAt(0) == 'q') System.exit(0);
System.out.println("mef"+ss);


try {

// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc dbc:mayank";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();



//these two statements does not execute durin the program

int m;


m= st.executeUpdate("insert into mayank values(ss) ");

ResultSet rs;

rs= st.executeQuery("select class,name from mayank ");


conn.commit();

while(rs.next())

{
String n= rs.getString("name");
String c = rs.getString("class");
System.out.println(n + " " + c);
}


}

catch (Exception e)

{
e.printStackTrace();
/*System.err.println("Got an exception! ");
System.err.println(e.getMessage());
*/
}







}
} // end main
/**
* reads a line from STDIN
*/
public static String getLine () {
StringBuffer buf = new StringBuffer(80);
int c;
try {
while ((c = System.in.read()) != -1) {
char ch = (char) c;
if (ch == '\n') break;
buf.append(ch);
}
}
catch (IOException e) {
System.err.println(e);
}
return (buf.toString());
}
}
this program is not compiling........
plzz help...

hi..
i have tried a program using java applet and
jdbc dbc bridge.....values will be entered through
the applet...NOW the program is not compiled
the error displayed is
{ expected

public class Test extends Applet implments ActionListener
plzz help.....

****************************************************************


[edited to add code tags]
[ September 26, 2005: Message edited by: Jeanne Boyarsky ]
i want to use prepared statement for entering values
and connect it with an applet....the values will be
entered from the applet.....i tried with inheritence
concept, also with different object, but it didnt work..
help me in doing this.....
how should i proceed now...
plzz help..




[edited to add code tags]
[ September 25, 2005: Message edited by: Jeanne Boyarsky ]
13 years ago
thanks ....
it really worked...
please advice me how to procede
further in passing values from an applet
to this application..
i have just started with jdbc
and tried some basic programs
i have tried used statement and preparedstatement
to connect to MS ACCESS ..
connection is is established in both the cases
i can retrieve the values form the database but
problem is entring values
can you please give a sample code of a program
of inserting and viewing values from a database in
MS ACCESS....
i have just started with JDBC
i tried a simple program for viewing and entring
values in MS Access.....in the below code i can retrieve
the values but cannot enter .....plzzz help




import java.sql.*;
import java.awt.*;


class Net2
{

public static void main(String ar[])


{
try {

// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc dbc:mayank";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();
ResultSet rs ;


//these two statements does not execute durin the program

//int m;


//st.executeUpdate("insert into mayank values('NITS') ");



rs = st.executeQuery("select class from mayank ");

conn.commit();

while(rs.next())
{
//System.out.println("ass");
System.out.println(rs.getString("class"));
//System.out.println("ass");

}


}

catch (Exception e)

{
e.printStackTrace();
/*System.err.println("Got an exception! ");
System.err.println(e.getMessage());
*/
}
}
}