How Can I Retrieve SQL Statement From The User ?

Hi
I want to know, how can I make the user can enter the SQL statement from himself ?? in this code he can't enter it. Only he can display the SQL that i wrote it...
this is my Code:
import java.sql.*;
public class db_testing {
     static final String DRIVER = "com.mysql.jdbc.Driver";            
     static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
     public static void main(String[] args) {
          Connection cn=null;
          Statement st= null;
          ResultSet rset=null;
          try{
               Class.forName(DRIVER);
               cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
               st=cn.createStatement();
               rset=st.executeQuery("select * from employee");
               ResultSetMetaData metadata=rset.getMetaData();
               System.out.println("The begining: ");
               for(int i=1;i<=metadata.getColumnCount();i++)
               System.out.print(metadata.getColumnName(i)+"\t");
               System.out.println();
               System.out.println();
               while(rset.next()){
               for(int i=1;i<=metadata.getColumnCount();i++)
               System.out.print(rset.getObject(i)+"\t\t");
               System.out.println();}
          catch(Exception e){
               e.printStackTrace();
          finally{
               try{
               cn.close();
               st.close();
               rset.close();
               catch(Exception e1){
                    e1.printStackTrace();
}

The following changes in the code will make the user to give the input
import java.sql.*;
public class db_testing {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
public static void main(String[] args) {
Connection cn=null;
Statement st= null;
ResultSet rset=null;
try{
Class.forName(DRIVER);
cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
// st=cn.createStatement();
// rset=st.executeQuery("select * from employee");
PreparedStatement pstmt=null;
pstmt=cn.prepareStatement("select * from employee where id=?");
pstmt.setInt(1,Integer.parseInt(args[0]));
rset=pstmt.executeQuery();
ResultSetMetaData metadata=rset.getMetaData();
System.out.println("The begining: ");
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(metadata.getColumnName(i)+"\t");
System.out.println();
System.out.println();
while(rset.next()){
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(rset.getObject(i)+"\t\t");
System.out.println();}
catch(Exception e){
e.printStackTrace();
finally{
try{
cn.close();
st.close();
rset.close();
catch(Exception e1){
e1.printStackTrace();
}

Similar Messages

  • How can I retrieve music tracks from the cloud?

    I deleted music from my library expecting it to now be available in the cloud.
    When I search in purchased items in iTunes and click on the item, it tells me that the original file is no longer available.
    I am not expecting the file to be available just the music track/album etc.
    How can I retrieve music tracks from the cloud?

    Hello, GregMarshall05. 
    Thank you for visiting Apple Support Communities. 
    Here are the steps on how to download your past purchases.
    Download past purchases
    http://support.apple.com/kb/ht2519
    Cheers,
    Jason H.

  • How can I retrieve deleted emails from the trash?

    How do I retrieve deleted emails from the trash?  I have not emptied the trash.

    Take a look at this post. Several posts should apply: https://discussions.apple.com/message/23461582#23461582

  • How can I retrieve my iBooks from the cloud?

    When I tap on the iBooks app the library is blank.  My books are not there anymore.  How can I retrieve them from the cloud?

    Are these books you purchased (using the same Apple ID you are using on your iPad) in the iBooks Store?
    If so, open iBooks, click "Store", then "Purchased" and you can re-download them from there.

  • How can i retrieve deleted photos from the ipod and stream

    We inadvertantly deleted all photos from the Ipod not realizing it would also delet them on the PC Stream.  Is there any way to retrieve them?

    If you backed-up the iPod the restore from backup
    iOS: How to back up and restore your content
    Otherwise a data recovery company may be able to get them. Not cheap.

  • How can you retrieve photo's from the time capsule(airport)

    Hi
    I recently had a problem with my mac and had to archive my stuff and put the operating system back on my computer.
    I 'lost' everything however I have been able to get some things back from the time capsule (airport) from previous backups. I can not find my photo's and they are the most important things I want back on my computer.
    Can anyone help? I have tried various things but still can't find them.
    thanks Lorraine

    If you did an Archive and Install, look for your "Previous System" folder and check for iPhoto in it.

  • How to retrieve SQL statement in the CR 2008

    I'm using Crystal Reports 2008 in MS Visual Studio 2008, how can i retrieve SQL statement from *.rpt file, i have tried this code, but it doesn't work:
    ReportDocument rdReport = new ReportDocument();
    rdReport.Load("Reports/EmployeeTest.rpt", OpenReportMethod.OpenReportByTempCopy);
    CrystalDecisions.ReportAppServer.Controllers.RowsetController rsController;
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rdClient = rdReport.ReportClientDocument; // on this line it throws an exception "The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."
    CrystalDecisions.ReportAppServer.DataDefModel.ISCRGroupPath rdGroupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
    string temp;
    string sql;
    rsController = rdClient.RowsetController;
    sql = rsController.GetSQLStatement(rdGroupPath, out temp);
    maybe i'm doing something wrong ?
    thanks

    Hello Ludek,
    when I try to get the report from the session I got an error like this (I am using State Server Session mode i.e out proc in my application)
    ReportClientDocument     'reportDocument.ReportClientDocument' threw an exception of type 'System.InvalidOperationException'     CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument {System.InvalidOperationException}
    +base     {"The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."}     System.SystemException {System.InvalidOperationException}
    StackTrace     "   at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ReportClientDocument()"     string
    so is it the problem of not opened with RAS. Does installation of RAS solves the problem, If so Is it a free-ware or needs to be purchased.
    Ashok

  • How can i retrieve deleted sms from my iphone

    how can i retrieve deleted sms from my iphone 4s?

    If you backed up your iPhone after the texts were made and before you deleted them you can Restore them in iTunes from your backup.

  • How can I retrieve deleted videos from my iPad 2?

    How can I retrieve deleted videos from my iPad 2?

    Did you backup your device after you took the video but before you deleted it?  If so, restore your device with that backup.  If not, then there's no way to retrieve that video.

  • How can I retrieve pictures, lost from my iphone during a backup?

    How can I retrieve pictures, lost from my iphone during a backup?

    The photos could have gone a couple of different places ...but it is unlikely that they are lost forever.  It kind of depends how your Backup was done.  With many Computer-based iTunes connections, your Computer Photo App will actually open first when you connect your iPhone and the photo transfer will happen between the iPhone and the App.  Assuming that isn't what happened in your case, but you did Backup on iTunes, you could reconnect to iTunes and then click on your iPhone button on the Computer screen ...typically the iTunes Summary screen will show up ...but you can tab-through the various iTunes Screens and find the Photo page.  You could check your options and see if you have a Manual Sync setting regarding iTunes to iPhoone ...this would mean you have to select the Photos you want to download to the iPhone during the Sync. 

  • How do you save "game state" so the user can continue next time?

    I'm not sure what the correct game terminology is for this, but how do you save "game state" so the user can continue next time?
    This seems like a pretty important feature for building some games, we don't want users to have to start over everytime.
    Any ideas if this is possible?

    Check out my blog post on the PersistenceManager:
    http://www.unitedmindset.com/jonbcampos/2010/11/01/flex-4-5-persistencemanager/
    This will help you understand how to store the data. When the app starts up again get the state information from the persistencemanager and reset you game to the state you need. It requires a bit of code for the startup, but it is relatively simple.

  • How can i retrieve my photos from i cloud ?

    how can i retrieve my photos from i cloud ?

    Welcome to the Apple community.
    Photo stream is not available at iCloud.com. In order to see the photos taken on your new iPad, you need to use another iOS device, mac or PC which is logged into your iCloud account.

  • How can i retrieve deleted folder from DMS?

    How can i retrieve deleted folder from DMS? please reply this question.

    Hi there,
    check the below link...hope it helps
    http://just-download.com/free/sapdmsdocuments+deleted/

  • How can I retrieve deleted messages from Skype?

    How can I retrieve deleted messages from Skype? I tried going to Users then application support but the folder is empty, so I'm stuck I don't know what to do?

    Try the Microsft Skype forums
    You can also try a disk file recovery program like Disk Warrior.

  • How can i retrieve deleted notes from iphone4 with no back up

    how can i retrieve deleted notes from iphone4 with no back up

    No Backup?
    Simply put, you can't.
    I won't rub salt into it anymore, but I guess you have just learned the importance of backing up your information.
    A mistake we've all made (once).

Maybe you are looking for