3, ఏప్రిల్ 2012, మంగళవారం

SOME OBSERVATIONS WHILE DEVELOPING THE JDBC CONCEPTS FOR AN APPLICATION


We are doing programming with java some important points to be remember
The projects having several classes if you want the data of the one class to another you simply create destination class with the constructor(what are the arguments or data or text field contents) in the source class after the present class visibility is set to false
Source class{………..
destination d=destination (JTextFeild.getText();Integer.parseInt(JTextField.getText());

…this is in the form from text to integer for ex:- no of fields in the text field here String but in the destination you use that as depending on that number of the label fields or text fields you want to create  you have to convert and pass this nubet to the for loop

in the for loop depending on you can create specified number of the text fields and labels combo boxes and also set their bounds and all put together in single take we can add to the content pane without adding manually   while creating combo boxes or textboxes you remember you have e to use one static array for storing the label or text what ever it may be and the array of pointers I.e.

not only creating the memory for the array for storing the names of the labels or text fields or combo boxes but indidually that buttons or contents of the array you indidually allot memory


here the program contains 1)login page implementation for this another class to call login page ,after login 4)another class design to implement to ask which table in the database and also how many fields to store and their data types also you can select form the combo box then you have the potations in this frame clear or store or retrive or delegate like …

.

Another frame is to be implement for the displaying of the database and another 2 frames depending on your requirement aspects and also one point to remember you are implementing the so many classes in the same program or complex programs after writing few lines then immediately compile for error handling other wise screen will fill with full of errors by scrolling it is too difficult for rectification like adding of the buttons or components after designed to the content pane and for setLayout(null); setting the boundaries for the items ,actionlisteners ,setbackgrounds and foregrounds and here addItem();  here setEchochar not work to fill login page with **** but insetd here we can use the PasswordFill() 



while some time you will forget the implementation of the action Listener to the frame ,window listener depending the application( this )    action listener to the buttons and textfields form the text obtain getText(); form the method itemStateChanged
               
actionPerformed() from this getActionCommand(); to obtain which button is activated and what is its content of the button or label



JFrame.EXIT_ON_CLOSE for the closing of a frame
And in the above program before display you have to implement to another FRAME which contain the class for connecting instructions to the data base

While writing programs mostly use constructor implementation for default execution and you want to use the variables in all methods then you declare them as private section which is global to all methods
Points to be remember while doing with database programming
JPasswordField   pf=new JPasswordField() ;here this displays the ‘*’ symbols for each character by deafult


pf.setEchoChar(‘#’); here we are specifying the # symbol while typing the password
operator.addSeparator(); it will separates the menu items with line
if we want to add the item to the menubar c.add(); in swings concept but in the frame format c.addItem();
by using this we setbounds to the items as we like where we want to place locations
but serially we add for that java provides one class setJMenuBar(mb);  


here are 5 types of the error message provides the java and their corresponding symbols
error message
question message
1.information message no symbol   arguments Table,message,WindowTitle  OK button only
2.inputdailogbox it contains on dialog box for inputting and it will returns the inputted message StringFormat  and the label for meesage,OK,CANCEL buttons and TextField();
it takes arguments as NULL,CENTER,Table Created Sucessfully for display message WINDOW TITLE
(for errormessage or dialog window or any informationWindow for that name and corresponding symbol)


getColoumnCount();
getColoumnLabel(i);   Array
getColoumnType();  this is an integer value
getColoumnTypeNames(); this return the number1,varchar2,…….but not return the data type size

in oracle while reading the string we place it in the ‘   
in the table how many fields obtain from METADATA class
for example       rm.getColoumnName(i)+”===è”+rm.getColoumnNameType();


Class selectdemo
{
public static void main(String args[])
{
try
{…………………………………….



ResultSet rs=s.executeQuery(“select *from student”); when we exeuate this statement not contain the coloumn names these are also retrived by the same statement but stored in a separate class the below given
ResultSetMetaData   rm=rs.getMetaData();//  this class maintains the howmany coloumns and their names in the array of Strings format  getColoumnCount,getColoumnLabel byspecing in the forloop we obtain that metadata and also one more important thing is why this data maintain separately of the coloumn names one way is data abstraction by seeing this MetaData every one easily can understand instead the only designer
Int col=rm.getColoumnCount();
For(int i=1;i<=col;i++)
System.out.println(rm.getColoumnLabel(i)+”\t”);
While(rs.next())
{
rs.close();   c.close()it is better after the completion of the operations to close it not affects the single user environment but in the network it may troubles you
}
}end of the try
here next function is pointed the starting that means records like 1,2,3… it points not 1 here which is the first record instead it points nil like stack pointer if inserts then it points the next empty location which is a new element is to be inserted basically next() is implemented in this fashion is to implement error handling if a query returns nil data then it will raise exception by placing the return of Boolean value in the while statement but in this we cannot accesses the previous records in the meanwhile already visited here the random access is not possible when it reaches to the result set end the next() function returns the false value
catch(Exception e)
{e.printStackTrace();}
}end of the main
}end of the class

//in this program I am explaining about the prepared statement about  the database connectivity in java
import java.sql.*;
import java.io.*;
class AlterDemo
{
public static void main(String args[])
{
int r,s1,s2,s3;
String n;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("Jdbc:Odbc:ramu1","scott","tiger");
PreparedStatement ps=c.prepareStatement("insert into student values(?,?,?,?,?)");
DataInputStream   k=new DataInputStream(System.in);
System.out.println("enter the serial no");
r=Integer.parseInt(k.readLine());
ps.setInt(1,r);
System.out.println("enter the name to be inserted");
n=k.readLine();
ps.setString(2,n);
System.out.println("enter the maths marks");
s1=Integer.parseInt(k.readLine());
ps.setInt(3,s1);
System.out.println("enter the physics marks");
s2=Integer.parseInt(k.readLine());
ps.setInt(4,s2);
System.out.println("enter the chemestry marks");
s3=Integer.parseInt(k.readLine());
ps.setInt(5,s3);
ps.execute();
System.out.println(" row inserted successfully");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("\n the exception raised");
}
}}

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి