|
-
July 13th, 2008, 04:37 AM
#1
My Problem With Jtable
hi,
i have problem with jtable to display data from db into table and here's the code that diplay data in console so what is the update on code to display data in jtable
Code:
import java.sql.*;
public class JdbCgetConnection2{
public JdbCgetConnection2(){
getConnection();
System.out.println("Connection establish");
System.out.println("---------------------");
}
public static void main(String []args){
new JdbCgetConnection2();
ResultSet allInfo = null;
try{
allInfo = getAllInformation();
while(allInfo.next()){
String s = allInfo.getString("id1");
String s1 = allInfo.getString("name");
System.out.print(s+"\t");
System.out.print(s1+"\t");
System.out.println();
}//end of while stmt
}//end of try stmt
catch(Exception e){
System.out.print("no");
}//end of catch stmt
}
//get Connection
private static Connection getConnection()
{
Connection con = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:db1";
con = DriverManager.getConnection(url);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
System.exit(0);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
System.exit(0);
}
return con;
}
//get all Information from table
private static ResultSet getAllInformation()
{
Connection con = getConnection();
try
{
Statement s = con.createStatement();
String select = "Select id1,name "+"from Tb_Info";
ResultSet rows;
rows = s.executeQuery(select);
return rows;
}
catch (SQLException e)
{
System.out.println(e.getMessage()+"error here");
}
return null;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|