jdbc & sql related project

jdbc & 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 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
View Answers

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 - JDBC
jdbc & 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 - JDBC
JDBC 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 Project
Related 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 query
JDBC 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 problem
JDBC 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 jdbc
query 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
start debugging problems related to the JDBC API
start debugging problems related to the JDBC API  How do I start debugging problems related to the JDBC API
project related question
project 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 - JDBC
key constraints in SQL server  Does SQL have a FOREIGN KEY constraints in a Table
sql - JDBC
SQL joins queries   Hi, can anyone give me the couple of SQL joins queries with examples
sql-jdbc
sql-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 - JDBC
SQL 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
".txt" to sql with JDBC
".txt" to sql with JDBC  how to insert ".txt" into sql result[BLOB] with JDBC
creating jdbc sql statements - JDBC
creating 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 - JDBC
Connectivity 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 - JDBC
JDBC 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
sql query - JDBC
sql query  I need a SQL query to add data into database
Connections with MicroSoft SQL - JDBC
Connections 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
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect. Thankyou
Connectivity with sql in detail - JDBC
Connectivity with sql in detail  Sir/Madam, I am unable to connect the sql with Java. Please tell me in detail that how to connect. Thankyou
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 - JDBC
SQL 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 - JDBC
java-sql  how to convert excel file into sql database usin java programming
jdbc odbc sql server exception
jdbc 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 - JDBC
Help 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 query
JDBC- 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 query
JDBC- 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 IDE
SQL 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 - JDBC
project  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
upload SQL BLOB and CLOB - JDBC
upload SQL BLOB and CLOB  Please explain upload SQL BLOB and CLOB
Version of com.foundationdb>fdb-sql-layer-jdbc dependency
List of Version of com.foundationdb>fdb-sql-layer-jdbc dependency
UNICODE or SQL statement issue - JDBC
UNICODE 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
Maven Dependency fdb-sql-layer-jdbc >> 1.9-3-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-3-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-4-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-4-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-0-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-0-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-1-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-1-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-1-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-1-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-1-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-1-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-3-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-3-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-4-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-4-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-5-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-5-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 1.9-5-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version1.9-5-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-0-jdbc41
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-0-jdbc41 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.0-1-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.0-1-jdbc4 in your project
Maven Dependency fdb-sql-layer-jdbc >> 2.1-0-jdbc4
You should include the dependency code given in this page to add Maven Dependency of com.foundationdb >> fdb-sql-layer-jdbc version2.1-0-jdbc4 in your project

Ads