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

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 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

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