Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Buttons Connection for SQL with Applet  RSS feed

 
Siddheh Desai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,
I request you to tell me that which aprroach should I used to connect database (SQL) by clicking Buttons. i have Done Buttons Programming in applets. When I attempt to run SQL Creat table Code, I got Run Time Error
I used following code.

import java.sql.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ButtonDemo extends Applet implements ActionListener
{
String msg=" ";
Button yes,no,maybe;

public void init()
{
yes=new Button("Yes");
no=new Button("No");
maybe=new Button("Undecided");

add(yes);
add(no);
add(maybe);

yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
String str = ae.getActionCommand();

if(str.equals("Yes"))
{
String url = "jdbc dbc:COFFEES";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

} catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try
{
con = DriverManager.getConnection(url,"sa","");

stmt = con.createStatement();
stmt.executeUpdate(createString);

stmt.close();
con.close();

} catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
}
else if(str.equals("No"))
{
msg="You pressed NO.";
}
else
msg="Yor pressed UNDECIDED.";
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,6,100);
}

}
 
Joe Ess
Bartender
Posts: 9414
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be polite to share the error message so we can see what is going wrong.
 
Ryan McGuire
Ranch Hand
Posts: 1123
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
It would be polite to share the error message so we can see what is going wrong.


Funny. That's the thing Paul Sturrock requested in reply to the duplicate message in the JDBC forum.

Ryan
[ June 20, 2005: Message edited by: Ryan McGuire ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!