Reputation: 21893
I'm trying to do the following:
String dbURL= "jdbc:oracle:thin:@HOST:PORT:DB,USERNAME,PASSWORD";
//Statement stmt = conn.createStatement(dbURL);
conn.createStatment is expecting 3 parameters, not just 1 string so i get an error. is it possible to have them all in one string and pass it? I know it's not the right way to go about this particular problem but i'm asking for future reference as well.
Edit: my mistake. i mean
Connection conn = DriverManager.getConnection(URL)
Upvotes: 0
Views: 230
Reputation: 6411
Working with JDBC requires several steps. Usually they are:
I have a feeling you're not sure about JDBC basics. Take a look at the JDBC tutorial.
Upvotes: 0
Reputation: 47183
As others have pointed out, what you are doing just won't work. Use this:
String dbURL= "jdbc:oracle:thin:@HOST:PORT:DB,USERNAME,PASSWORD";
Connection conn = DriverManager.getConnection(dbURL);
PreparedStatement ps = conn.prepareStatement("your SQL");
The first line is your database URL.
The second line will get the actual connection using the db URL.
The third line will let you get the prepared statement from your connection.
This pattern is widely used, so you should use it too (unless you're in Java EE, where obtaining db connections works a bit differently).
Upvotes: 2
Reputation: 43088
Use PreparedStatement
instead. It is supposed to get SQL query as a parameter. Your connection string is supposed to be passed to DriverManager.getConnection()
method
Upvotes: 3