Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Java ODBC

Name: Anonymous 2011-04-03 23:00


package homework3;
import java.sql.*;
import javax.swing.JOptionPane;

public class hw3_2 {

    public static void main(String args[])
    {
       
        //Variables for database insert set by JOptionpane data input
        String course = JOptionPane.showInputDialog(null, "Course ID:");
        String desc = JOptionPane.showInputDialog(null, "Description:");
        String cred = JOptionPane.showInputDialog(null, "Credits:");
        int credits = Integer.parseInt(cred);     
       
        //DB Connection
        String url = "jdbc:odbc:registrar";
        Connection con;
        Statement stat;
       
        String insert;
        insert = "INSERT INTO courses VALUES ('" + course + "','" + desc + "','" + credits + "');";
       
        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, "", "");
            stat = con.createStatement();
            ResultSet rs = stat.executeQuery(insert);
            
            System.out.println("Data successfully added to Courses table.");
           
            stat.close();
            con.close();
        }
           
        catch (SQLException ex)
        {
            System.err.println("SQLException: " + ex.getMessage());
        }
    }
}


The insert query works as intended, however I'm getting "SQLException: General error" from the 2nd catch - what error is it catching?

Name: Anonymous 2011-04-04 0:10

Bumping, because let's face it, the 2 threads above this are utter spam shit.

Name: Anonymous 2011-04-04 0:11

>>1
A general one.

Name: Anonymous 2011-04-04 0:22

>>2

Fuck you asshole. You dumb piece of shit

Name: Anonymous 2011-04-04 0:23

>>4
Don't bump threads you don't like. Don't bump threads you like. Don't bump.

Name: Anonymous 2011-04-04 0:24

>>5

I thought sage was a polite thing to do, not a down voting system

Maybe you should go back to the imageboards.

Name: Anonymous 2011-04-04 0:27

>>6
It's not a downvoting system, is >>4 being impolite and not a real answer to >>1. Neither is relevant to the thread.

Name: Anonymous 2011-04-04 0:27

>>6
U MENA >>1

Name: Anonymous 2011-04-04 0:30

>>8
The thread being shitty still better than http://dis.4chan.org/read/prog/1301889967 and http://dis.4chan.org/read/prog/1301887599 is another reason to not bump it: you're not being polite to the thread and its OP, you're being polite to the whole board by not shitty on its frontpage.

Name: Anonymous 2011-04-04 1:10

Are you guys retarded

Name: Anonymous 2011-04-04 1:42

>>10

lul, u mad?

Name: Anonymous 2011-04-04 1:58

Yeah, it's hard to get a proper response from a forum full of retards like yourself.

Then again, I didn't have high expectations, considering all of the other threads are about useless bullshit, full of idiots bickering amongst themselves for no real reason.

Name: Anonymous 2011-04-04 2:08

package homework3;
If we help you, you'll never learn. Doing things yourself is a wonderful learning experience.

Name: Anonymous 2011-04-04 2:14

>>13
Sounds like a fancy way to say "I don't know."

The fact is, the program works as intended for the assignment. I could simply remove the try/catch all together, the teacher wouldn't give a fuck, and I'd still get a 100.

This is for my own benefit, and I'm not going to benefit by spending 3 hours of my life figuring out this problem, so fuck off if you're useless online as well as irl.

Name: Anonymous 2011-04-04 2:16

>>14
This is for my own benefit
Nice one. If it was you'd be figuring it out yourself and not asking other people for help, since you know it's for your own benefit and not for a high grade.

Name: Anonymous 2011-04-04 2:17

>>15

This just in, you can no longer learn from others!

Seriously, you're fucking stupid. Just stop talking and save yourself the embarassment.

Name: Anonymous 2011-04-04 2:23

stop fooling yourself and write more oneliners to begin with
DriverManager.getConnection("jdbc:odbc:registrar","","").createStatement().executeQuery(insert);
fucking side-effect programming

Name: Anonymous 2011-04-04 2:24

>>16
This just in, you can no longer learn from others!
You can. But the way to do it is by reading a book not by asking people on the internet to spoon feed you the answer (which is found easily using Google anyway).
http://mitpress.mit.edu/sicp/ here's a book recommendation
Seriously, you're fucking stupid.
You can't figure out why a 30 line Java program doesn't work properly.

Name: Anonymous 2011-04-04 2:25

>>17

Everyone does it differently. I for one have an easier time programming this way.

Sure, it may be more efficient to have 1 line instead of 2, but unless the program is fucking huge it won't really matter in the overall scheme of things.

Name: Anonymous 2011-04-04 2:27

>>18

What's the difference between someone telling me the answer to something, and me reading about it in their book?

Nothing, other than that you're a huge faggot, and this is more convenient given I have provided my specific example, and I'm not digging through unrelated examples to solve a problem I don't care to spend half my life figuring out in the first place.

Fuck.
You.
Faggot.

Name: Anonymous 2011-04-04 2:30

I'm not digging through unrelated examples to solve a problem I don't care to spend half my life figuring out in the first place.

But I thought this was for your own benefit. Why do you hate learning?

Name: Anonymous 2011-04-04 2:32

>>21

If you had any intention of being helpful, you would've simply gently pointed me in the right direction without spelling it out for me.

The fact is, you're just a bad troll with nothing better to do than talk shit to random people on the internet, as though it would get you anywhere in your meaningless, basement-dwelling life.

Please do everyone online a favor and unplug your internet connection, turn off your computer, and go play in traffic.

Name: Anonymous 2011-04-04 2:34

>>20
This is really pathetic.  You obviously have no interest in knowledge and don't belong in any kind of intellectual field, let alone on this board.  You're just spewing shit out of your fingertips because you want an easy grade and/or think anyone gives a fuck what you think.

Name: Anonymous 2011-04-04 2:34

>>22
gently pointed me in the right direction without spelling it out for me
But you wanted the answer spelled out for you. Otherwise you would have found it yourself. Why are you so angry?

Name: Anonymous 2011-04-04 2:39

>>23
lol.

You want the truth? Truth is, I think Java is a shit language, and all I want to do is solve this small problem and be done with it. I have no intention of arguing with some fuckwit who thinks they're the shit on a shitty 4chan offshoot.

I don't want an "easy grade," as I've said before the program successfully accomplishes what it is meant to do for the assignment. You're simply trying to validate your reason for being a complete asshole, and you're pissed off that I'm not buying it. The fact is, asking for quick help online is easier than reading books and other stupid "learning" methods.

You're dumb to forgo the easy method in favor of the difficult one, as you're clearly deluded into believing that "learning" can only be achieved through the latter. Perhaps you should "learn" that you are ignorant when it comes to such things.

You know, it's funny...I'd wager you're a real piece of shit IRL too.

Name: Anonymous 2011-04-04 2:45

>>24

More baseless assumptions on your part. Your mistake here is that you assume that anyone who desires the help of others needs to have everything spelled out for them. Somehow you believe that by not learning myself, that I expect you to simply hand me the answer, no questions asked. You should be careful about making such uninformed assumptions; your ignorance is showing.

Name: Anonymous 2011-04-04 2:50

>>25

Wow shut up nerd I bet you cried like a bitch when your mother told you you couldnt suck her breasts anymore and you were like 15 years old when this happened making it even more pathetic fuck you kid you dont know me

Name: Anonymous 2011-04-04 2:52

>>27

Well, it's about time you realized that I've been shitting on you on you intellectually with my arguments.

Name: >>24 2011-04-04 2:53

>>25
Just a heads up, that guy isn't me. However
reading books and other stupid "learning" methods
Man you're killing me.
>>26
How is my ignorance showing? You just wanted the answer (since it's a quick fix) for a good grade because you're too stupid to even do a simple Java program properly. Perhaps you should stick to Visual Basic and online tutorials since reading books and other stupid "learning" methods is too advanced for you.

Name: Anonymous 2011-04-04 2:56

>>29

That's alright, what I said still stands.

How am I killing you? I'm simply saying that there is no valid reason for me to choose a more difficult method of learning over an easier one.

It's interesting how you can gauge someone's maturity online, based on the fact that their argument begins with personal insults, such as how "stupid" I am in your eyes. Surely you are the perfect being, and have never required help in order to solve a problem in your lifetime! No? Didn't think so.

Name: Anonymous 2011-04-04 2:58

>>28
Calling other people faggots is not beating them intellectually.

Name: Anonymous 2011-04-04 3:00

>>28

Shut the fuck up you cocksucking faggot

Name: Anonymous 2011-04-04 3:01

>>31

You are correct, however I am still waiting for some sort of intelligent response regarding your blatant assumptions.

You: U want halp u no lern
Me: Argues to the contrary
You: U want halp u no lern

That isn't quite how arguments work. You see, you should offer additional points which support your argument, rather than simply restating it, which is essentially what you have done here.

While I'm sure you'll most likely lie to me, I'm compelled to ask what you do for a living.

Name: Anonymous 2011-04-04 3:01

>>30
When I required a quick fix I didn't tell other people online I was ``trying to learn''. I said I wanted a quick fix. The reason I recommended books is because they're much better than online tutorials and the shitty teaching at most universities. Of course you have to not be retarded to figure this out and unfortunately you don't fit the criteria.

Name: Anonymous 2011-04-04 3:03

>>25
I have no intention of arguing with some fuckwit who thinks they're the shit on a shitty 4chan offshoot.
And yet, it's exactly what you're doing since >>10/>>12.

Name: Anonymous 2011-04-04 3:05

>>34

And here you have dug yourself so deep in the hole that you surely will be unable to escape without help from another.

If you will take note of all of my posts since the original post, not once have I denied that I wanted quick fix, nor did I say that I am doing this in order to learn.



Likewise, you don't fit the criteria for a person I would consider intelligent enough to be able to develop and support an argument. Clearly we both have areas in which we can better ourselves.

Name: code less, create more 2011-04-04 3:07


 -> showInputDialog ["Course ID:" "Description:" "Credits:"]
    |> map "\'$x\'" |> infix "," |> ["INSERT INTO courses VALUES (" @? ")"]
    |> fold "$?$??" |> sqlQuery

Name: Anonymous 2011-04-04 3:07

>>36
You said you were doing this for your own benefit (aka LEARNING) and not doing this for an easy grade (aka QUICK FIX).

You're on anonymous textboard do you really need to pretend this much?

Name: Anonymous 2011-04-04 3:10

>>37
THIS THREAD IS OFFICIALLY SHIT NOW.

Name: Anonymous 2011-04-04 3:13

>>38

This is almost comical. You assume that the only possible "personal benefit" in this case is by learning something. You also falsely assume that a "quick fix" involves an easy grade, even though I have established multiple times that the SQL error itself has no basis on my grade at this point.

The fact is, I view a quick fix as anything which would eliminate this error, simply for the [extremely OCD] purpose of having a clean, error-free the program, that is all. Nothing more, nothing less.

Name: Anonymous 2011-04-04 3:14

Let's settle this.

OP is a faggot for not saying they wanted a quick fix.
Anon is a faggot for not simply providing them their quick fix.

You are both faggots for keeping this shitty thread bumped.




SOLUTION:
Anon: Give him his goddamned quick fix
OP: Thank the faggot for it and stfu

Name: Anonymous 2011-04-04 3:26

>>41
getConnection
public static Connection getConnection(String url,
                                       String user,
                                       String password)
                                throws SQLException

Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
    url - a database url of the form jdbc:subprotocol:subname
    user - the database user on whose behalf the connection is being made
    password - the user's password
Returns:
    a connection to the URL
Throws:
    SQLException - if a database access error occurs


Source: http://download.oracle.com/javase/1.4.2/docs/api/java/sql/DriverManager.html - Retrieved on 04 April 2011 09:25 GMT+1

Name: Anonymous 2011-04-04 3:28

>>42
I meant
getConnection
public static Connection getConnection(String url,
                                       String user,
                                       String password)
                                throws SQLException


Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
    url - a database url of the form jdbc:subprotocol:subname
    user - the database user on whose behalf the connection is being made
    password - the user's password
Returns:
    a connection to the URL
Throws:
    SQLException - if a database access error occurs


Source: http://download.oracle.com/javase/1.4.2/docs/api/java/sql/DriverManager.html - Retrieved on 04 April 2011 09:25 GMT+1


>>1
Check your database.

Name: Anonymous 2011-04-04 3:29

>>39
It was shit directly from OP-post, because Jewa is based on mathematical classes.

Name: Anonymous 2011-04-04 3:39

It wasn't a problem with the database, just something I overlooked.

Original:
stat.executeQuery(insert);
New:
stat.executeUpdate(insert);

Because that was SO fucking hard to tell me. Useless.

Name: Anonymous 2011-04-04 3:44

>>45
Because that was SO fucking hard to figure out yourself. Useless.

Name: Anonymous 2011-04-04 3:44

>>45
That was SO fucking hard to search in the docs >>42-43. Useless documentations, everyone should work just for me!

Name: Anonymous 2011-04-04 3:44

>>47
Forgot my sage.

Name: Anonymous 2011-04-04 3:49

>>46

It is when you're tired and could give 3 shits about java

you never told me what you do

Name: Anonymous 2011-04-04 3:59

>>49
Because you're a lazy faggot. The way things are going you're going to write Java the rest of your life probably.

Name: Anonymous 2011-04-04 4:14

>>50

and again you ignore my question about what you do for a living

inb4 'student'

Name: Anonymous 2011-04-04 4:18

>>51
student

Name: Anonymous 2011-04-04 4:38

>>51
student

Name: Anonymous 2011-04-04 4:53

>>51
Egypt.

Name: Anonymous 2011-04-04 4:54

>>51
Read SICP.

Name: Anonymous 2011-04-04 6:49

This thread is already a raging inferno, but I'd like to point out I knew what was wrong after one look at the javadocs despite not knowing how to just Java ODBC.  So, OP, if you want any genial advice, just learn how to parse every single facet of the javadocs and not take a line of it for granted.

Name: Anonymous 2011-04-04 10:29

>>56
lol.

Name: Anonymous 2011-04-04 11:03

Java
ODBC


now you have TWO problems

Don't change these.
Name: Email:
Entire Thread Thread List