code using jdbc,odbc,swing,MySql classes to create front-end of any jdbc that allows the user to select any database from a list and execute any sql query related to the selected database e.g if a student database is selected by the user from the list then he should be able to execute any query related to student database i.e. the odbc driver should support this sql query so that it can be executed and required data can be displayed in a seperate frame
June 15, 2010 at 4:50 PM
Hi Friend,
Try the following code:
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class Application{
private JScrollPane scrollpane = null;
JList list;
DefaultListModel model;
public Application(){
model = new DefaultListModel();
JFrame frame = new JFrame("Databases");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306";, "root", "root");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("SHOW DATABASES");
while(rs.next()){
model.addElement(rs.getString("Database"));
}
rs.close();
st.close();
con.close();
}catch(Exception ex){}
list = new JList(model);
scrollpane=new JScrollPane(list);
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
String selection = list.getSelectedValue().toString();
try{
final Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/"+selection,"root";, "root");
DatabaseMetaData meta = con.getMetaData();
ResultSet rs = meta.getTables(null, null, "%", null);
DefaultListModel model1 = new DefaultListModel();
while(rs.next()){
model1.addElement(rs.getString(3));
}
final JList list1 = new JList(model1);
JScrollPane scrollpane1=new JScrollPane(list1);
JFrame f=new JFrame("Tables in the selected database");
f.add(scrollpane1);
f.pack();
f.setVisible(true);
list1.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event) {
if (!event.getValueIsAdjusting()) {
String table = list1.getSelectedValue().toString();
try{
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from "+table);
while(res.next()){
System.out.println(res.getString(1)+" "+res.getString(2));
}
}
catch(Exception exc){}
}
}
});
}
catch(Exception ex){}
}
}
});
JPanel panel = new JPanel();
panel.add(scrollpane);
frame.add(panel);
frame.setSize(400, 400);
frame.setVisible(true);
}
public static void main(String[] args){
Application tt = new Application();
}
}
Hope that it will be helpful for you.
Thanks
Related Tutorials/Questions & Answers:
jdbc & sql related project - JDBCjdbc &
sql related project code using
jdbc,odbc,swing,MySql classes to create front-end of any
jdbc that allows the user to select any database from a list and execute any
sql query
related to the selected database e.g
JDBC related Problem - JDBCJDBC related Problem Hey plz check out the following code... = "
jdbc:odbc:" + ds;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver...("
jdbc:odbc:access");
Statement st = con.createStatement();
int c
Advertisements
Related to ProjectRelated to Project how speech to text
project can be make in java?
Please tell me the coding part therapeutically i know i have to use java speech api which offer two technology
1. speech recognization
2. speech syenthesis
JDBC related queryJDBC related query How to merge two resultset of two different queries, wherein both the resultset(after query execution)gives an integer value as its column
JDBC ODBC related problemJDBC ODBC
related problem i WANT HELP
RELATED TO
JDBC CONNECTIVITY WITH MS ACCESS..
HERE IS MY FULL CODE...
import java.awt.Container;
import... con;
con = DriverManager.getConnection("
jdbc:odbc:Digambar
query related to jdbcquery
related to jdbc hello,
i have done my database connection successfully ie db2 with RAD. but while running my application i am not able to fetch the data so please suggest and help me
project related questionproject related question 1- how to insert a date through hibernate
2- how to insert exact time ,date separetly in the data base for current time date
sql - JDBCkey constraints in
SQL server Does
SQL have a FOREIGN KEY constraints in a Table
sql - JDBCSQL joins queries Hi, can anyone give me the couple of
SQL joins queries with examples
sql-jdbcsql-jdbc how to execute select query using prepared statement
jdbc - SQL
cannot add or change a record because a
related record is required in
table
jdbc - SQL
cannot add or change a record because a
related record is required in
table
sql - JDBC://www.roseindia.net/
jdbc/jdbcconnectivity.shtml
You will find the solution.
Thanks
Sql - JDBCSQL Statement and prepared statement What is Statement and prepared statement in SQL Statement and prepared statement are the interfaces declared in JAVA.SQL.While you connecting to a database these are required.If
creating jdbc sql statements - JDBCcreating
jdbc sql statements I had written the following program...=DriverManager.getConnection("
jdbc:odbc:second");
stmt=con.createStatement...)
Hi friend,
i think, connection problem. i am sending
jdbc Connectivity with sql in detail - JDBCConnectivity with
sql in detail Sir/Madam,
I am unable to connect the
sql with Java. Please tell me in detail that how to connect...;
String url = "
jdbc:mysql://localhost:3306/";
String dbName
JDBC connection and SQL Query - JDBCJDBC connection and
SQL Query Hi,
I'm reading a all files one after the other in a directory in java. storing the values in an array of string each time. Now I'm trying to execute a query to insert those values into an oracle
Connections with MicroSoft SQL - JDBCConnections with MicroSoft SQL How to Connect Java and MS
SQL??
Actually i used below code i got SQLException and class not found...
import...;
Statement st = null;
ResultSet rs = null;
String url = "
jdbc My sql - JDBC,emp_vertical,emp_supervisor.
i need a
JDBC program with driver mangager... out.
i need insert and update queries. Hi friend,
For
JDBC...://www.roseindia.net/
jdbc/
jdbc-mysql/SelectRecords.shtml
http://www.roseindia.net/
jdbc jdbc sql exception.jdbc sql exception. import java.sql.*;
import java.io.*;
class...("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("
jdbc...");
Connection con=DriverManager.getConnection("
jdbc:odbc:student
SQL QUERY - JDBCSQL QUERY I m running a query using apache tomcat the
sql query is on adding an employee in the database whenever i click on add after inserting the values i am getting a java.lang.nullpointer exception
java-sql - JDBCjava-sql how to convert excel file into
sql database usin java programming
jdbc odbc sql server exceptionjdbc odbc
sql server exception Hi,
I am trying to use
sql server with java
jdbc odbc but I am getting this exception
java.sql.SQLException: [Microsoft][
SQL Server Native Client 10.0][
SQL Server]Incorrect syntax near '@P1
Help on JDBC and my SQL 5 database - JDBCHelp on
JDBC and my
SQL 5 database Dear Sir,
I had create a statement for the
JDBC as shown below:
try... the connection
c = DriverManager.getConnection
("
jdbc:mysql
my question is related to my project viz my question is
related to my
project viz Sir, my
project is based on MR tracking system developed using struts framework, it has been developed in Net Beans the whole
project is working except a jsp page named dayplan.jsp
JDBC- SQL spatio-temporal queryJDBC-
SQL spatio-temporal query Any one give me a
JDBC sql query for my spatio temporal query?
Trajectory table
OBJID PLACE
7 H
8
Q
9 W
10... as shown in above. I want a spatio-temporal query using
JDBC-
SQL to retrieve
JDBC- SQL spatio-temporal queryJDBC-
SQL spatio-temporal query Any one give me a
JDBC sql query for my spatio temporal query?
Trajectory table
OBJID PLACE
7 H
8
Q
9 W
10... as shown in above. I want a spatio-temporal query using
JDBC-
SQL to retrieve
SQL STATEMENT in JDBC in NETBEANS IDESQL STATEMENT in
JDBC in NETBEANS IDE Iam using NETBEANS IDE. Iam developing a bank application. Using
JDBC in SERVLETS
For the withdraw function, "bal" and "ano" are user inputs when i wrote like,
st.executeQuery("UPDATE
project - JDBCproject code for front-end of any
JDBC compatible database Hi Friend,
Try the following code:
1)register.jsp:
Registration Form
First Name:
Last Name:
User Name:
Password:
Address
UNICODE or SQL statement issue - JDBCUNICODE or
SQL statement issue Hi again............
I have got something new that...........
i was using MS Access as the database with my... nothing ......
I had also change my backhand to
SQL SERVER but retrieves same