Hi,
I wrote a Table in Oracle to create a table in Oracle.
Code:import javax.swing.JOptionPane; import java.sql.*; public class JDBCProgram { public static void main(String args[]) { JOptionPane.showMessageDialog(null,"Welcome to JDBC Demo"); int choice = -1; String userid="scott"; String password = "tiger"; do { choice = getChoice(); if (choice != 0) { getSelected(choice, userid, password); } } while ( choice != 0); System.exit(0); } public static int getChoice() { String choice; int ch; choice = JOptionPane.showInputDialog(null, "1. Create Coffees Table\n"+ "0. Exit\n\n"+ "Enter your choice"); ch = Integer.parseInt(choice); return ch; } public static void getSelected(int choice, String userid, String password) { if(choice==1) { createCoffees(userid, password); } } // Create Coffees Table public static void createCoffees(String userid, String password) { String url = "jdbc:odbc:bob"; // String url = "jdbc:mySubprotocol:myDataSource"; ? 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"); //Class.forName("myDriver.ClassName"); ? } catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "userid", "password"); stmt = con.createStatement(); stmt.executeUpdate(createString); stmt.close(); con.close(); } catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } } }//End of class
When I run this program I am getting the following error.
SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:could not resolve service name
When I cross checked to see if I am able to log in SQL Plus using
Username: scott
Password: Tiger
Host String: bob
It works fine


Reply With Quote


Bookmarks