Mysql java question?
Hello,
I am writing a java program to connect with mysql, the database two tables: order and items.
In the order the orderNo is a unique value, and appears again the items table for each book ordered.
Could any advise, if I wanted to delete the orderNo from the order table, and also delete all the records in the items table with the same orderNo, could I achieve this in one sql statement?
Thanks
table (order):
orderNo
table (items):
orderNo
bookname
quantity
price
example for orderNo 2:
DELETE items,order FROM items,order WHERE order.orderNo=2 and items.orderNo=2Haven't tried this myself, though.
regards
Similar Messages
-
MySQL + Java doesn't work
I've been trying to get a connection using MySQL and Java without luck, I've been messing with every solution I have found in google without luck. It worked the last time I used mysql + java a few months ago (in Ubuntu) but now I can't even get a connection.
MySQL works with PHP, MySQL Administrator and CLI but I just can't get it to work with Java.
Has anybody been able to run Java applications that use JDBC + MySQL in Arch?
The stack trace I get is like the following and it changes a little bit if I use different versions of the Connector
java.sql.SQLException: Server connection failure during transaction.
Due to underlying exception: 'com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1934)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:483)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:992)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2709)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at MySQLConnectTest.main(MySQLConnectTest.java:12)
Last edited by karmapolice (2007-05-22 20:48:25)http://bugs.archlinux.org/task/7256
Added a bug report -
Java Question... please help
I am running Snow Leopard (mac os x version 10.6.8)
For the past couple of years I've played gin in yahoo games.
Yesterday when I entered the gin lobby ...the font was so tiny
I wasn't able to read it. I checked Java on my computer and
it is enabled, however I just realized when I go into the gin
lobby... there is no java icon on the dock. Since the font size
is fine in all other applications, I am presuming this is a Java
issue.
Help if you are able.. please and thanksHuh? Is this a Java question? Where's the Java? I just see a little JavaScript. Do you know how to use servlets and JSPs?
Jesper -
What kind of Java questions can I ask?
Here's a change:
I want to interview some good java people. I have lots of Java questions in mind which I could ask them, however fellow JavaGuru's
I would like some potential questions from you which I could ask someone who claims he/she is a good java programmer??
I am asking because I want to be as fair as possible to the applicant and not ask them questions which I think are tough etc...Touchy subject.
The language is not as important, as understanding programming concepts.
So fine, when the programmer's horizont involves some abstraction levels.
If a programmer can write an UML class diagram for a linked list.
If a programmer knows a design pattern Singleton.
If a programmer can write his/her own single linked list class with sorted insertion.
Language concepts:
- Why:
import java.util.*;
Map map = new HashMap();
- Answer:
Hiding the choice of implementation (HashMap) by using the more general
interface Map.
Don't expect much on an interview though. The situation might not be
adequate to distinghuish between the good and the bad apples.
Talking code is a good starting point, code of your making unfortunately.
A good programmer will hesitate to show really useful code.
A bad programmer might have stolen his/her code.
The problem you might have, that you are in search of an expert, not
having the expertise in-house. In that case you might get a better
picture, talking about which IDE would be opportune, whether he/she
has experience with the source version system CVS, what would his/her
ideas be about coming projects.
That would establish a common line of communication. -
Interesting Java Questions. Need answers Pls
Hi All,
I have come accross few java question, could any one please provide best answers please?
1. Why the wait() method is there in the Object class? Not in the Threads?
2. Why JDBC has all interfaces & not classes?
3. Which type of collection do u prefer to make the incoming objects in sort order?
4. Why the hasCode() method should be implemented if we are overiding the equals(0 method?
Please provide me best answers ASAP.
Girish.Kdo u prefer tohttp://www.catb.org/~esr/faqs/smart-questions.html#writewell
How To Ask Questions The Smart Way
Eric Steven Raymond
Rick Moen
Write in clear, grammatical, correctly-spelled language
We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal - in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes. -
XLetview mysql java.lang.notFoundException
I am programming for TV, I made a basic program that connects to my local database, but when run with the xLetView I get this error when running this line Class.forName ("org.gjt.mm.mysql.Driver ");
mysql java.lang.notFoundException
Place the mysql driver in the folder 'jars' of xLetview but nothing works.
I work with a basic but not with the xLetView.
Helpme!!!There is no such exception. What does the error message really* say? No guessing.
-
I began playing with JDBC a few days ago. I set up a database using mySQL and wrote a simple java program that will connect to it. Works good from the computer that holds the database.
I try and run the same program from my secondary computer which does not have mySQL or ODBC mySQL drivers, I get com.mysql.jdbc.Driver for an error message. (Trying to access the database on my main computer via ip/databasename)
My Question is, do you HAVE to have mySQL or Connector/ODBC installed on a computer if you wish to connect to a database on other computer??
Here's where it prints the error message...
try
Class.forName("com.mysql.jdbc.Driver");
catch (Exception e)
JOptionPane.showMessageDialog(null, "ERROR = " + e.getMessage());
I use this as my url..
private final String url = "jdbc:mysql://122.122.122.122:3306/test123";
Say I want to make a simple web applet that will
access a database on my computer. The only way my
vistors to my website will be able to access the
database via the web applet is by having mySQL JDBC
driver installed on their computers?yes.
however.
you can package up the JDBC driver as part of your jar with your applet so it doesn't require the user to "install" anything. it's just part of your applet. -
Let's say that I am making a java program that connects to a Mysql database and uses the database "MyDatabase".
Forgive me, but I am relating this to a Microsoft Access database.
The database is not on a network, but is (or will be installed) on the user's machine. In otherwords, the database will be on the user's machine and the changes to the database will only affect that user.
If I am to let a user use this program, will they have to also have Mysql installed for the program to access the database and pull information from it?
--Thanks!Let's say that I am making a java program that
connects to a Mysql database and uses the database
"MyDatabase".[snip]
The database is not on a network, but is (or will be
installed) on the user's machine.[snip]
If I am to let a user use this program, will theyhave
to also have Mysql installed for the program toaccess
the database and pull information from it?Yes.
(if you are asking if the code could directly
access/manipulate MySQL datafiles without going
through the MySQL program, I suppose in theory you
could, but I seriously doubt you really want to)The reason being is that it would be a client database for their own use, as oppose to sharing the database with others.
In any case, Thanks!
Next question: is there any place where I could go to find code that would treat the Mysql database as a client database (so far, the code that I found requires Mysql to be installed and running in the background on the user's machine)? -
1) A program written in Java is supposed to be multi-platform. However, I notice alot of programs I've seen written in Java are distributed to specific systems using different file extensions. The Windows version usually uses the .exe extension and I'm wondering how come they don't use the default .class extension? One major company is Borland for their JBuilder. They had a Windows version long before a Linux version even though I hear it was created in Java.
2) Is there a free install program for Java or are the only ones commercial products?
3) Is there a personal database available for Java that will work on all platforms? In my Internet Programming with Java class we used mySQL but I don't want to use a server database let alone one that will require a seperate install.
4) Is there a free multi-platform IDE for Java (not counting just a text editor)?
5) Can you universally access a system with Java? Ex. If I wanted to load an application with Java in Linux and Windows do I need to write two seperate routines on how to do this or does Java have a built in function? If I wanted to delete a file is this written universally the same?1) A program written in Java is supposed to be
multi-platform. However, I notice alot of programs
I've seen written in Java are distributed to specific
systems using different file extensions. The Windows
version usually uses the .exe extension and I'm
wondering how come they don't use the default .class
extension? One major company is Borland for their
JBuilder. They had a Windows version long before a
Linux version even though I hear it was created in
Java.Java programs are packaged (wrapped) to allow invocation using a .exe extension. It is not mandatory, nor is it a function provided within the native Java libraries. Standard Java is packaged in .jar files that allow execution within a Windows (or other) environment. Environmental setup is necessary to allow the O/S to find the Java libraries. This is a simple process that includes additions to the PATH and CLASSPATH environment variables.
2) Is there a free install program for Java or are the
only ones commercial products? I believe installAnywhere has a stripped down version of an installer that you can use for free. They also have a pay-per version that provides more extensive functionality.
3) Is there a personal database available for Java
that will work on all platforms? In my Internet
Programming with Java class we used mySQL but I don't
want to use a server database let alone one that will
require a seperate install.There are several Java embeddable SQL compliant databases including Cloudscape and Pointbase. These are written and deployed as Java libraries, and can run within the same JVM as your application or in a seperate JVM on the same machine, or on a seperate machine with IP connectivity. I'm sure there are more, these are just two that I have used. I don't know that there are any free implementations of embeddable databases for Java (but just wait awhile, things change all the time).
4) Is there a free multi-platform IDE for Java (not
counting just a text editor)?For personal use, there is Borland JBuilder personal that can be downloaded and used for free. I personally use Sun ONE Studio CE (formerly Forte for Java) which is also free but uses a lot of resources, so be sure you have an adeqaute workstation to run it on. Again, I'm sure there are others, these are just the ones I have had success with.
5) Can you universally access a system with Java? Ex.
If I wanted to load an application with Java in Linux
and Windows do I need to write two seperate routines
on how to do this or does Java have a built in
function? If I wanted to delete a file is this
written universally the same?I'm a little unclear on your question, but you can invoke a seperate process (application) from Java using the O/S native interface through a Java function call. A seperate method is probably not necessary for each O/S, just different parameters passed to the exec function.
File I/O and file manipulation can be done using Java, and does not have to be O/S specific (but you have that option if you want to). -
im not sure if this is the right forum or not so i apologize in advance if its not
first off if you store some table(like a 2 demensional array) of data in some file type (not sure what type to use for this)
is there a way to pull a single piece or a row of data out of the file withought loading the entire file to memory
for example if i have the file
1.5.8.3.9.12
7,4,8,9,2,4
3,10,3,4,1,7
is it possible for me to say take out just thee 10 withought dumping the entire file to memory or the row that 10 is on
second question
is it possible to make a database using only java like replicate mysql just using javaaphxps wrote:
im not sure if this is the right forum or not so i apologize in advance if its not
first off if you store some table(like a 2 demensional array) of data in some file type (not sure what type to use for this)
is there a way to pull a single piece or a row of data out of the file withought loading the entire file to memoryNot really. You don't have to retain the entire file in memory, but you'll probably have to scan through it to find what you want. RandomAccessFiles might come in handy, possibly.
for example if i have the file
1.5.8.3.9.12
7,4,8,9,2,4
3,10,3,4,1,7
is it possible for me to say take out just thee 10 withought dumping the entire file to memory or the row that 10 is on
second question
is it possible to make a database using only java like replicate mysql just using javaReplicate MySQL exactly? Or just write pure Java databases?
If the two questions are, as I suspect, related, I strongly suggest you give up on this endeavour for the time being. It's about 50 squillion times more complicated than simply pulling some data out of a file efficiently. -
public static void main(String[] args)
..anyone know the statement as above could be start at begining , so what is the (String[ ] args) mean in java ?
in my ideas of this statement is
publc : indicates the statemean can be used as all class , this is open for public use
static mean the main method can used as class method
void indicate that the statement return nothing
main indicate any class should be run this first.
so my question what is the function of (String [ ] args) ? // one string array call args ?String[] args is indeed an array of Strings called args. The reason it's there is to collect any arguments passed to your code when you start it.
eg. if you have a class called TestClass and you called it from the command line like this:
java TestClass exam tomorrow oh shite
.......then the args array would hold the four Strings:
exam
tomorrow
oh
shite -
By using the JDBC form wizard, I generated a swing program. Along with the java code, there is a form file which looks like an xml file. My question is how to complie and run the java source code without a forte4j IDE?
ThanksOne thing is you need the jdbc in your classpath or specify at runtime. Search compiler in the forte help menu - to see options.
execution : <specify at runtime>
java -classpath:.;postgresql.org Program
-- above for postgresql driver residing in same directory as Program.class
compile : javac Progam.java or javac -classpath .;postgresql.org Progam.java
Ray -
TextSamplerDemo.java question
I took the TextSamplerDemo from http://java.sun.com/docs/books/tutorial/uiswing/components/text.html and stripped it down to the one thing I have a question about. Given the code below, how do I implement the toolbar button to make selected text turn bold? I've been beating my head againt this one for a couple of days now and getting nowhere.
Any help would be deeply appeciated.
--gary
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*; //for layout managers and more
import java.awt.event.*; //for action events
public class TextSamplerDemo extends JPanel
implements ActionListener {
private String newline = "\n";
protected static final String textFieldString = "JTextField";
public TextSamplerDemo() {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JToolBar toolBar = buildToolbar();
add(toolBar);
//Create a text pane.
JTextPane textPane = createTextPane();
JScrollPane paneScrollPane = new JScrollPane(textPane);
paneScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
paneScrollPane.setPreferredSize(new Dimension(250, 155));
paneScrollPane.setMinimumSize(new Dimension(10, 10));
add(textPane);
public void actionPerformed(ActionEvent e) {
private JTextPane createTextPane() {
String[] initString =
{ "This is an editable JTextPane, ", //regular
"another ", //italic
"styled ", //bold
"text ", //small
"component, " + newline, //large
"which supports embedded components..." + newline,//regular
newline + "JTextPane is a subclass of JEditorPane that " + newline +
"uses a StyledEditorKit and StyledDocument, and provides " + newline +
"cover methods for interacting with those objects."
String[] initStyles =
{ "regular", "italic", "bold", "small", "large",
"regular", "regular"
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
addStylesToDocument(doc);
try {
for (int i=0; i < initString.length; i++) {
doc.insertString(doc.getLength(), initString,
doc.getStyle(initStyles[i]));
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
return textPane;
protected void addStylesToDocument(StyledDocument doc) {
//Initialize some styles.
Style def = StyleContext.getDefaultStyleContext().
getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "SansSerif");
Style s = doc.addStyle("italic", regular);
StyleConstants.setItalic(s, true);
s = doc.addStyle("bold", regular);
StyleConstants.setBold(s, true);
s = doc.addStyle("small", regular);
StyleConstants.setFontSize(s, 10);
s = doc.addStyle("large", regular);
StyleConstants.setFontSize(s, 16);
private JToolBar buildToolbar() {
JToolBar toolBar = new JToolBar();
toolBar.setRollover( true );
toolBar.setFloatable( false );
JButton boldButton = new JButton("Bold");
boldButton.setToolTipText( "Set selected text to bold" );
boldButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// code here to make selected text bold
toolBar.add( boldButton );
return toolBar;
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("TextSamplerDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new TextSamplerDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();try this, but im'not sure.
StyleContext styleContext = StyleContext.getDefaultStyleContext();
Style def = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
Style bold = styledDocument.addStyle("bold", def);
StyleConstants.setBold(bold, true);into the listener of your component insert this:
int start = getSelectionStart();
int len = getSelectionEnd() - start;
styledDocument.setCharacterAttributes(start, len, bold, true);by gino -
Hello:
I'm looking for some guidance on a few things I am confused on. Can somebody tell me or point me in the right direction on how you would write and equivalent compound statement for
x = 2 * x;
sum = sum + num;
y = y / (x +5);
lastly
What type of input would I use for :
import java.util.*;
public class Strange
static Scanner console = new Scanner (System.in);
public static void main (String[ ] arg)
int x;
int y;
String name:
x = console.nextInt ();
name = console.nextLine ();
y = console.nextInt ();
I appreciate any guidance and help provided on this. I'm struggling to wrap my head around some of these things.eaolson wrote:
BigDaddyLoveHandles wrote:
This is obviously a homework question. Please don't expect anyone here to do your homework for you.Well, if you notice, he's asking for "guidance" and for people to "point him in the right direction". He's not stating a problem and demanding a solution like so many others. If you ask me, he's asking for help with homework in exactly the right way.
For the first question, I would suggest reviewing this section and the following ones of the Java Tutorials:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op1.html
I don't understand what the second question is asking for.In reply #2 the OP tried to clarify the second question:
Well, I'm tasked wtith stating "what type of input the progragms requires and in what order the input must be provided" for the program I stated. >Beyond that, I'm not sure either and that's why I'm looking for help. "Looking for help", eh? -
EDID and LUT - a java question
Hi all!
I just got my Mac Mini two days ago. I need some help in accessing certain informations to a java app I'm ought to write. I tried to google 'em up, but I got stuck. Maybe someone here could help me?
1. How can I get EDID from my display? I've seen there's something called read-edid under linux, but I don't really know how close a relative Tiger is to linux/BSD.
2. How can I write to LUT on my Mac?
I suppose there are some libraries, that I can use, but I can't find them
If not, maybe someone could direct me to a C library, so I can hopefuly run it via JNI.
Any help would be greatly appreciated.
TIA,
Pabloblue-rose wrote:
i don't see someone who want to help me =/ ,, if u don't want to ,, it's up to you ,, but there is no need for these words which u said to me ,, it really hurts ,, thanks all anyway =( ,,Seriously though, we help those that show that they are willing and able to do some work first. All you've posted was a classic "homework dump", and these are the typical responses to homework dump questions. Lesson learned.
Maybe you are looking for
-
Cannot open image files in PS CS3 from Bridge CS3
Cannot open file in Photoshop CS3 (10.0.1) from Bridge CS3 (2.1.1.9) Tried choosing File>Open and double clicking the image thumbnail Error dialogue box pops up and reads: Windows cannot find\C:\Program Files\Adobe\Photoshop CS\Photoshop.exe I wouldn
-
Fonts not appearing correctly on other clients
I know this has been an ongoing issue for everyone using Apple's mail client but I'm going to ask it here again. There has been many posts but many unanswered posts. How can I get mail.app to send e-mail out using say..."Arial" and have it show up as
-
Update shows which is not mine
I have had this problem for several months now. I have taken the Macbook Pro 13" (mid 2012) to 2 different Apple stores and consulted with the "Geniuses" there. No one has been able to solve this problem for me. I keep getting a notice of an update o
-
Shutdown with no reason!!
i was working on my macbook pro and it shutdown for no reasoned, no warring message. the power cord was more hot than usual. When i restart my computer the time was rest in 2000. i had reprove some only permission. google chrome don't let me surf th
-
Procedure compilation Error.......
Hi , I am getting an error while compiling the procedure...Please help me out.. create or replace procedure generate_test_file RETURN NUMBER IS CURSOR curEmployee IS SELECT empno, ename,sal FROM Emp; --Line to output sOutputLine VARCHAR2(4000); uFile