How to connect JTable to a database to show it?

al salamo 3alaykom w ra7mato allahe w barakato....
I tried a lot to connect a JTable to a database to show it.....but i couldnt......
in the clas where i create it i wrote this code
Class General extends JFrame{
// private declaration like:
private Vector heading = new Vector();
private Vector data= new Vector();
private JScrollPane jScrollPane1 = new JScrollPane();
private JTable jTable1 = new JTable(data,heading);
public General() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
try{
Connection conc;
DriverManager.registerDriver((Driver)Class.forName("com.mysql.jdbc.Driver").newInstance());
conc = DriverManager.getConnection("jdbc:mysql://localhost/tdiary?user=root&useUnicode=true&characterEncoding=utf8");
Statement stmt = conc.createStatement();
ResultSet rs= stmt.executeQuery("SELECT * FROM diary");
String n1 = new String();
String add = new String();
String tele1 = new String();
String tele2 = new String();
String tele3 = new String();
String tele4 = new String();
String mobi1 = new String();
String mobi2 = new String();
String mobi3 = new String();
String mobi4 = new String();
String mail1 = new String();
String Details = new String();
while(rs.next())
n1 = rs.getString("Name");
add = rs.getString("Address");
tele1 = rs.getString("Tel1");
tele2 = rs.getString("Tel2");
tele3 = rs.getString("Tel3");
tele4 = rs.getString("Tel4");
mobi1 = rs.getString("Mob1");
mobi2 = rs.getString("Mob2");
mobi3 = rs.getString("Mob3");
mobi4 = rs.getString("Mob4");
mail1 = rs.getString("Mail");
Details = rs.getString("Details");
heading.addElement("name");
heading.addElement("Tel");
heading.addElement("Mobile");
heading.addElement("Address");
heading.addElement("E-mail");
data.addElement(n1);
data.addElement(tele1);
data.addElement(mobi1);
data.addElement(add);
data.addElement(mail1);
System.out.println(data);
} catch (Exception k){
k.printStackTrace();
//and then i continued the code ......
//but the table doesnt appear....why?....and if there is another way to do it...plz tell me
i hope someone could help me coz i got mad from this problem.
thanx
al salamo 3alaykom w ra7mato allahe w barakato

Hi,
Please use code formatting when you post code. See the formattings tips:
http://forum.java.sun.com/help.jspa?sec=formatting
I can't see that you have added your table or scroll pane to any content pane. That's why it isn't displayed.
Kaj
Ps.
You have lots of assignements of Strings when you are declaring your variables, it's useless, just set them to null.

Similar Messages

  • How to connect to a remote database in a lan??

    Hey guys......! I need to connect to a remote msaccess database in a lan and import its data into my mysql database.I know how to connect to a msaccess database using ODBC.But I don't know how to connect to a remote database without creating dsn in the machine where database is.One thing more...I want to know, how can I import data into my mysql database?? Is there any query for that or simply I have to select data from msaccess database and insert into tables of my database??Please, send me the source code in the forum itself and explain also.This is the last feature of my project.So I need to do it as soon as possible.

    If the mdb file in LAN, Just map the network drive.[Windows Explorer/Tools/Map Network Drive] in your system from which we need to access the remote mdb. Then go to ODBC Data Source Admin.. and create a new data source[Microsoft Access Driver] . After clicking the Select button, you will find a Network Drive will be visible on your Drives drop down. Select the map Drive, If not visible then just click the Network button there and map the network path where the mdb files reside. And use the JdbdOdbcDriver class to connect from java.

  • How to connect Java to oracle Database Express Edition?

    Anyone can help me?
    How to connect JAVA TO ORACLE DATABASE EXPRESS EDITION?

    I suggest you to read this article:
    http://wiki.oracle.com/page/JDBC
    Regards,
    Ricky

  • How To connect More Then One database

    How To Connect More the One Database In Single form.
    I want to use Access And Oracle In the Same Form.
    I want to Transfer data from Access file To oracle database.
    Chirag

    Hi,
    You can do this using EXEC_SQL package. Please see Note 115540.1 on metalink which describes how you can connect to Ms Access and Oracle using EXEC_SQL.
    Regards
    Kavitha Prakash
    Oracle Support

  • Members only area of website and how to connect it to existing database

    I am trying to create a members login section on an existing website. We have a MS Access database of clients, and I need the website login creation to be able to look at our database and only let the person create an account, if they are on that list. 
    I've successfully completed a walkthrough/tutorial on creating a members only area of a website, but that allows anyone and everyone to create an account. I need a way to force that check before the new user account is allowed. Any help will ge greatly appreciated!

    Hi,
    According to your description, I think your issue is more about how to connect to Access database from your web site, instead of Access development.
    Which type of connection do you want to use? Is it ADO.NET?
    If so, I suggest you posting in ADO.NET Managed Providers
    forum for more effective responses.
    If not, you can choose a proper forum based on the type of the connection or your developing language.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to connect to a specific database in SQL server

    Hi,
    How can I connect to a specific database in SQL server? I used the following statement. But my table is inserted to the 'master' database in the SQL server. How can I insert my tables to the specific database tahta I have created before?
    Connection con;
    String sURL = "jdbc:microsoft:sqlserver://SERVER_NAME:1433";
    con = DriverManager.getConnection ( sURL, sUsername, sPassword);

    Hi,
    When I use the syntax:
    String sURL = "jdbc:microsoft:sqlserver://SERVER_NAME:1433/DATABASE_NAME;selectMethod=cursor";
    it gives an error as follows:
    problems connecting to jdbc:microsoft:sqlserver://SERVER_NAME:1433/DATABASE_NAME;selectMethod=cursor:
    [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
    What is the way to connect to a specific database?

  • How to connect to Azure SQL database remotely (SharePoint 2013 BI)

    Hi,
    I am new to using Azure VM's and I am looking for advice. I have created and can connect to an Azure VM with a SQL Server 2012 installed on it (includes SSAS and SSRS). I connect to the VM using Microsoft Remote Desktop Connection.
    The problem I am having is connecting to the Azure database from a SharePoint BI site. Are there any good videos or websites that demonstrate how to setup an Azure VM so a user can access a database remotely.
    I hope you can help. 
    ATaylor

    Hello,
    To connect to the SQL Server Database from another computer, you must know the Domain Name System (DNS) name of the Azure virtual machine. For example: DNSName,portnumber such as SQLVM.cloudapp.net,57500.
    (Note: The port number is the public endpoint port which you can configure in the management portal for TCP communication with SQL Server on Azure VM.)
    As for datasource credentials, you can use a SQL Server authentication login: create a SQL Server login with password on the SQL Server instance.
    Reference:
    Complete Configuration steps to connect to the virtual machine Using SQL Server Management Studio on another computer
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • How to connect to an oracle database server from a linux server?

    Hi,
    I am a total newbie to oracle. At my work, I only know that there is a server with an oracle 10g database set up.
    I was provided with the hostname, oracle sid, port, username and password but i don't know how to connect to it, log on to it and do things on the database.
    Can anyone give me a pointer on how to get started (like how to log on to the server and start doing some simple things. )
    Any help is appreciated :)
    Thank you

    Goto your local Oracle install directory and then goto folder NETWORK/ADMIN
    cd ${ORACLE_HOME}/network/admin
    do you see a tnsnames.ora file there? If you edit that file in your favorite editor, you would hopefully see some entries there already setup. See if one of those entries contain the hostname, sid, port that was given to you. if it does, that name is what you will use:
    $ sqlplus username/password@name_of_tns_entry_you_found_aboveif not, then just duplicate an existing entry and change the relevant settings for your database, give it a new name and use it to connect.
    alternatively you can also use the "Net Configuration Assistant" application.

  • How to connect Java Application with database!

    Dear all, now I am create a dababase application. My database use JData Store. But I don't know how to connect application with it. Can you tell me this proplem?
    Thank!

    Do a google search for JDBC, or go buy a book.
    You will need a JDBC driver which supports your database. Or you might be able to use the JDBC-ODBC bridge if there's an ODBC driver for your database.

  • How to connect webdynpro application to database (Sql server)

    Hi Experts,
    Can someone suggest me how to connect webdynpro application to SQL Server. (Possibly in detail)
    Thanks Regards,
    Sandeep

    hi sandeep,
    here is a sample code which connects to a backend database Oracle; Connection is same for all DBs as you are using open sql commands.
    <b>   try {
         String eposta = wdContext.currentContextElement().getEposta();
         String tel = wdContext.currentContextElement().getTelefon();
         String company = wdContext.currentContextElement().getCompany();
         String message = " ";
         String onerikonusu = " ";
         String oneri_mdurum = " ";
         String oneri_odurum = " ";
         String oneri_bfaydalar = " ";
         String oncelik1 = " ";
         String uygulama = " ";
         String tarih = (new SimpleDateFormat("dd-MM-yyyy").format(new java.util.Date()));
         String saat = (new SimpleDateFormat("HH:mm:ss").format(new java.util.Date()));
         //java.sql.Date tarih = java.sql.Date.valueOf(creationDate);
         //java.sql.Time saat = java.sql.Time.valueOf(creationTime);
         if (wdContext.currentContextElement().getMesaj() != "")
            { message = wdContext.currentContextElement().getMesaj(); }
         if (wdContext.currentContextElement().getOneri_konusu() != "")
              { onerikonusu = wdContext.currentContextElement().getOneri_konusu(); }
         if (wdContext.currentContextElement().getOneri_mdurum() != "")
              { oneri_mdurum = wdContext.currentContextElement().getOneri_mdurum(); }
         if (wdContext.currentContextElement().getOneri_konusu() != "")
              { oneri_odurum = wdContext.currentContextElement().getOneri_odurum(); }
         if (wdContext.currentContextElement().getBekfaydalar() != "")
              { oneri_bfaydalar = wdContext.currentContextElement().getBekfaydalar(); }
         if (wdContext.currentContextElement().getOncelik() != "NULL")
              { oncelik1 = onceliktxt.toUpperCase(); }     
         if (wdContext.currentContextElement().getUygulama() != "NULL")
              { uygulama = app.toUpperCase(); }
       InitialContext ctx = new InitialContext();
       javax.sql.DataSource ds =
       (javax.sql.DataSource) ctx.lookup("jdbc/SAPEPPDB");
       java.sql.Connection con = ds.getConnection();
       con.setAutoCommit(false);
       java.sql.Statement stmt = con.createStatement();
         String sql;
          int rows;
          sql = "insert into tmp_feedbacks " +
               "(puid, name, tel, email, company, konu, oncelik, uygulama, mesaj, onerikonusu," +
               "oneri_mdurum, oneri_odurum, oneri_bfaydalar,tarih,saat) " +
               "values ('" + username + "', " +
                         "'" + name + "'," +
                         "'" + tel + "'," +
                         "'" + eposta + "'," +
                         "'" + company + "'," +
                         "'" + konutxt.toUpperCase() + "'," +
                         "'" + oncelik1 + "'," +
                         "'" + uygulama + "'," +
                        "'" + message + "'," +
                        "'" + onerikonusu + "', " +
                        "'" + oneri_mdurum + "', " +
                        "'" + oneri_odurum + "', " +
                        "'" + oneri_bfaydalar + "', " +
                        "'" + tarih + "', " +
                        "'" + saat + "' " +
         stmt = con.createStatement();
         rows = stmt.executeUpdate(sql);
         con.commit();
         stmt.close();
       catch(Exception e){
            IWDMessageManager msgMgr =
                    wdComponentAPI.getMessageManager();
       msgMgr.reportException(e.getMessage(),true);
       }</b>
    The value <b>ctx.lookup("<jdbc_pool>");</b> depends on your system id.
    if your system id is SID the the string has to be <b>jdbc/SAPSIDDB</b>
    you can check it via visual admin >> server >> services >> jdbc con.

  • How to connect servlet to mysql database

    Hi all,
    I am new to mysql. After many difficulty I have created a database with table in MySql. Now I want to connct it to a servlet. How do I do it?
    Can anyone tell me the steps, including the step to create MySql datasource
    thanks

    thanks for the reply. I know the basics of jdbc and can connect with sqlserver. Bt how to connect with Mysql? I mean what do I provide in dsn unless I create a MySql datasource. I cant find any tutorial which teaches how to create MySql datasource. Can you give me any link???
    thanks

  • How To Connect To Oracle 11g Database From Microsoft Excel

    Hi All,
    I have Windows7 64bit installed in my laptop.
    I have Microsoft Excel 2007 installed.
    I tried connecting to Oracle database ( This is not a local database).
    Navigation used:
    Data> From Other Sources > From Data Connection Wizard > Other/Advanced > Next > Microsoft OLE DB Provider For Oracle > OK
    Now I get a pop up to enter:
    username
    password
    server
    When I enter all the required details I get this error "ORA-06413 CONNECTION NOT OPEN"
    Is there no need to give PORT number?
    Thanks,
    Vishwamber Shetty

    Hi,
    Did you install oracle client on the machine? Can you do "tnsping <SID>"? Can you connect to DB using sqlplus ?
    Try using tnsname for server name.
    Connecting to Microsoft Data Sources Through ODBC Connection  This shows how to connect using ODBC connection. I think this would be more appropriate.

  • How to connect to a foxpro database

    im a newbie in java database connectivity. may i know how to establish a connection to a foxpro database using java. i am not sure of the codings needed

    Have a look at the JDBC tutorial. That should get you started.
    kind regards,
    Jos

  • How to connect to a MSSQL database thru EP

    I need to know how to connect a mssql database to EP.

    Hi Garry,
    In order to connect to an external database you have to create JDBC or BI JDBC systems:
    http://help.sap.com/saphelp_nw04s/helpdata/en/1f/bddf3d48b05d5ae10000000a11405a/content.htm
    Then, you can show the information into the database using simple "query iviews"
    http://help.sap.com/saphelp_nw04s/helpdata/en/f5/eb516b0e6a11d7b84900047582c9f7/content.htm
    or with developer tools like Visual Composer
    http://help.sap.com/saphelp_nw2004s/helpdata/en/42/efeca129e31bc7e10000000a11466f/content.htm
    Regards,
    Nacho

  • How to connect to secondary MSSQL database besides SBODemo

    I need to be able to connect to both the SBODemo database and another database in MSSQL while executing my add-on application (written in C#).  I have a working connection method for SBODemo, but need to know how to connect to the non SAP database at the same time. 
    Thanks,
    Nancy

    Use the standard .Net SQL connector: "System.Data.SqlClient.SqlConnection"
    Example:
    string myConnectionString = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
    SqlConnection myConnection = new SqlConnection(myConnectionString);
    string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
    SqlCommand myCommand = new SqlCommand(myInsertQuery);
    myCommand.Connection = myConnection;
    myConnection.Open();
    myCommand.ExecuteNonQuery();
    myCommand.Connection.Close();
    Search any .Net forum out there and you find tons of other eaxmples

Maybe you are looking for

  • BPM: Error while executing Open - Unexpected exception

    Hello! Everyone Can you please let us know if anyone has faced similar issue and any suggestion on resolving the below issue would be very helpful: We have been experiencing problem with opening BPM in our ESR; we are getting a Error while executing

  • How to send output of one Bapi to another Bapi??

    dear all,            I am having two BAPIs. From one Bapi I am getting value(Output) in one dropdown box.            Now my problem is how to give output of first BAPI(in drop down box) as input to second BAPI which should display in second drop down

  • Content Filters

    Content Filters have been selected  through My Verizon Security Suite; however, it blocks TV shows that I would like to watch.  How do I prevent this?

  • How to access iPhoto (8.1.2) files to delete?

    I have gone through all of my iPhoto files and deleted the ones I don't want, but when I let the screensaver run with everything in my "Pictures" folder, the deleted images still show up. Isn't there a way to access all copies of the photos in order

  • Slim needs gcc-libs not gcc has dep

    I just found out that slim needs gcc for a 57kb file. This file is in gcc which is 23mb. I just want know why this one file is not gcc-libs instead gcc. This is so people how don't need gcc will need to install it in order to get slim to work. Just m