Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC jdbc & sql related project
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


maria
jdbc & sql related project
1 Answer(s)      4 years and 7 months ago
Posted in : JDBC


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

Advertisement
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
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
Advertisements
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
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
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
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
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
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
sql - JDBC
SQL joins queries   Hi, can anyone give me the couple of SQL joins queries with examples
sql - JDBC
key constraints in SQL server  Does SQL have a FOREIGN KEY constraints in a Table
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
regarding mini project - JDBC
regarding mini project  i need to make a mini project using servlet and jdbc.pls help me with a real time application
project in java - JDBC
project in java  hi, i should do a project that enables a local cable operator to manage his customers. this should be done in java plz send me... friend, i am sending java project link, visit following link http
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
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
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
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
Advertisements
 

 

 

DMCA.com