Add to Favorites    Make Home Page 5545 Online  
 Language Categories  
 Our Services  

Home » Java Home » JDBC (Java Database Connectivity) Home » INTERACTION BETWEEN SQLSERVER AND SQL CLIENT

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title INTERACTION BETWEEN SQLSERVER AND SQL CLIENT
Author B. Rajavel
Author Email mhgsss [at] yahoo.com
Description communication between server and client .


Category Java » JDBC (Java Database Connectivity)
Hits 391862
Code Select and Copy the Code
//SQLSERVER import java.sql.*; import java.net.*; import java.io.*; public class SqlServer { public static void main(String []args) { BufferedReader br; ServerSocket ss; Socket s; int portno; String qry; Connection con; try { br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter portno:"); portno=Integer.parseInt(br.readLine()); ss=new ServerSocket(portno); System.out.println("Server waiting..."); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); while(true) { s=ss.accept(); new SqlServerReadData(s); } } catch(Exception e){} } } class SqlServerReadData implements Runnable { Connection con; Statement stmt; ResultSet r; ResultSetMetaData rm; Socket s; BufferedReader is; PrintWriter os; String qry,result,uname,pass,dsn; Thread t; int colcount; SqlServerReadData(Socket s) { try { this.s=s; is=new BufferedReader(new InputStreamReader(s.getInputStream())); os=new PrintWriter(s.getOutputStream()); //System.out.println("Username"); //uname=is.readLine(); //System.out.println("Passward"); //pass=is.readLine(); //System.out.println("dsn"); dsn=is.readLine(); String str="jdbc:odbc:"+dsn; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection(str,"",""); stmt=con.createStatement(); t=new Thread(this); t.start(); } catch(Exception e){} } public void run() { try { while(true) { try { qry=is.readLine(); if(qry.compareToIgnoreCase("quit")==0) break; if(!(qry.startsWith("select"))) { try { r=stmt.executeQuery(qry); os.flush(); }catch(Exception e){} } else try { r=stmt.executeQuery(qry); rm=r.getMetaData(); colcount=rm.getColumnCount(); for(int i=1;i<=colcount;i++) { result=rm.getColumnLabel(i); os.print(result); os.flush(); } os.println(""); for(int i=1;i<=34;i++) os.print("-"); os.println(""); while(r.next()) { result =""; for(int i=1;i<=colcount;i++) { result=result+" "+r.getString(i); } os.println(result); os.flush(); } r.close(); } catch(SQLException e){} catch(Exception e){} os.println("end"); os.flush(); } catch(Exception e){} } stmt.close(); } catch(Exception e){} } } //SQLCLIENT import java.sql.*; import java.net.*; import java.io.*; public class SqlClient { public static void main(String []args) { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));; BufferedReader is; PrintWriter os; Socket s; int portno; String qry,hostname,result,uname,pass,dsn; System.out.print("enter the hostname:"); hostname=br.readLine(); System.out.println("enter portno:"); portno=Integer.parseInt(br.readLine()); s=new Socket(hostname,portno); is =new BufferedReader(new InputStreamReader(s.getInputStream())); os=new PrintWriter(s.getOutputStream()); System.out.println("Username"); uname=is.readLine(); System.out.println("Passward"); pass=is.readLine(); System.out.println("dsn"); dsn=br.readLine(); os.println(uname); os.flush(); os.println(pass); os.flush(); os.println(dsn); os.flush(); while(true) { System.out.print("SQL:\>"); qry=br.readLine(); if(qry.equals("quit")) break; os.println(qry); os.flush(); result=is.readLine(); while(!(result.equals("end"))) { System.out.println(result); result=is.readLine(); } } os.println("quit"); os.flush(); os.close(); is.close(); s.close(); } catch(Exception e){} }

Related Source Codes

Script Name Author
Sending mail Using JavaMail to Yahoo and Gmail accounts sai prasad
Simple Program in Java to Implement Multithreading Satish.K
Simple Calculator in Java Using Remote Method Invocation Satish.K
Guest Book Application Using Servlets Satish.K
String Manipulation Using Stringification Satish.K
String Manipulation Using Stringification Satish.K
Moving Ball Application Using Java Beans Satish.K
Rapid Roll game subrahmanyeswararao
student mgm arpan
Sourav Datta
Download Manager Sagar
Address Book in Java Rahul Chouhan
address book using java database connectivity(jdbc-msaccess) shekhar bansal
sun Steganography B.Rajavel
Connecting Java with MS-Access - Inserting data in Aseem

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=647


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review