|
[quote name='Gashayija' date='14 Jun, 2009 - 01:24 PM' post='673856'] [quote name='jpete7683' date='22 May, 2009 - 08:32 PM' post='650730'] Have you writen the code to create a connection to the Database? i havent written code yet becouse i dont know how to go about it? how do you connect to database and selection,insert,delete to be enter in textArea and result from database to be displayed below the typed textarea [/quote]
here is my attechment of what i have done
import java.sql.*;
public class AllTableName{ public static void main(String[] args) { System.out.println("Listing all table name in Database!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db = "mydatabase"; String driver = "com.mysql.jdbc.Driver"; String user = "root"; String pass = "najah2"; try{ Class.forName(driver); con = DriverManager.getConnection(url+db, user, pass); try{ DatabaseMetaData dbm = con.getMetaData(); String[] types = {"TABLE"}; ResultSet rs = dbm.getTables(null,null,"%",types); System.out.println("Table name:"); while (rs.next()){ String table = rs.getString("TABLE_NAME"); System.out.println(table); con.close(); } } catch (SQLException s){ System.out.println("No any table in the database"); } } catch (Exception e){ e.printStackTrace(); } } }
Attached File(s)
import_java.doc ( 170k )
Number of downloads: 11
|