Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Database help in java

Jushua419Jushua419 Member Posts: 14
I'm currently in a java class this semester, the project we are supposed to do is print out in a Applet a list of people. She wants us just using drawStrings but that to me don't teach Crap. So I thought I'd add a database made in Microsoft Works Database. Below is the program and where and what the errors are. I tried the java board but no help yet there. IF someone can help I'd appreciate it. Thank you,


import java.sql.*;
import javax.swing.*;// Error #1 here package swing not found
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.lang.*;

public class databApp extends JFrame{ //Error #2 here super class of jFrame not found

private JTable DataTable;
private Connection Database;


public databApp () {
String url = "jdbc:odbc:customers";
String userID = "John";
String password = "settle";
Statement DataRequest;
ResultSet Results;


try {
Class.forName( "sun.jdbc.odbc.jdbcOdbcDriver");
Database =
DriverManager.getConnection(url,userID,password);
}
catch (ClassNotFoundException error) {
System.err.println("Cannot connect to the database." + error);
System.exit(1);
}
catch (SQLException error){
System.err.println("Cannot connect to the database" + error);
System.exit(2);
}
try {
String query = "Select * FROM customer";
DataRequest = Database.createStatement();
Results = DataRequest.executeQuery (query );
DisplayResults (Results );
DataRequest.close();
}
catch (SQLException error ) {
System.err.println("SQL eroor." + error);
System.exit(3);
}
setSize (500,200);
show();
}

private void DisplayResults (ResultSet DisplayResults)throws SQLException
{
boolean Records = DisplayResults.next();

if (!Records ) {
JOptionPane.showMessageDialog( this, "End of Data.");
setTitle ( "Process Completed");
return;
}
setTitle ("CUSTOMER NAMES");
Vector ColumNames = new Vector();
Vector rows = new Vector();
try {
ResultSetMetsData MetaData = DisplayResults.getMetaData();

for (int x =1; x <= MetsData.getColumnCount(); ++x)
ColumnNames.addElement (MetaData.getColumnName(x));

do {
rows.addElement (DownRow(DisplayResults, MetaData ));
} while ( DisplayResults.next());

DataTable = new JTable ( rows, ColumnNames );
JScrollPane scroller = new JScrollPane ( DataTable);
getContentPane().add(scroller, BorderLayout.Center);
validate();
}
catch (SQLException error ) {
System.err.prntln("Data display error." + error);
Systen.exit(4);
}
}
private Vector DownRow (ResultSet DisplayResults, ResultSetMetaData MetaData)
throws SQLException
{
Vector currentRow = new Vector();
for (int x = 1; x <= MetaData.getColumnCount(); ++x)
switch ( MetaData.getColumnType (x)){
case Types.VARCHAR :
currentRow.addElement(DisplayResults.getString(x));
break;
}
return currentRow;
}
public void Disconnect()
{
try {
Database.close();
}
catch (SQLException error){
System.err.println("Cannot break connection." + error);
System.exit(5);
}
}
public static void main ( String args[])
{
final conxtest link = new conxtest();
link.addWindowListener (
new WindowAdapter() {
public void windowClosing(WindowEvent WinEvent )
{
link.Disconnect();
System.exit (0);
}
}
);
}
}



Comments

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ______ ( http://forcoder.org ) free video tutorials and ebooks about { C, Visual Basic .NET, Scratch, Python, Assembly, Java, C#, Swift, Objective-C, Ruby, PL/SQL, R, PHP, Delphi, Visual Basic, Go, JavaScript, MATLAB, Perl, C++ Scheme, D, Scala, ML, Alice, Hack, LabVIEW, Dart, Awk, Julia, Lisp, Kotlin, F#, Logo, Ada, Fortran, Bash, Crystal, Transact-SQL, Rust, Prolog, FoxPro, SAS, VBScript, Clojure, COBOL, Lua, Apex, ABAP, Erlang } ____________

Sign In or Register to comment.