Accessing Oracle's strange mistake with JDBC

xiaoxiao2021-03-05  30

It turned out to use .NET SQL, last year, the company is ready to pick up an Oracle project, lending this opportunity to try Java, then find that Java is really a "professional"

Now I will take this wrong towel, let's take a look:

I suggested an application in the JBuilder 2005 trial version, and there is the following code in the init () event:

Class.Forname ("Oracle.jdbc.driver.Oracledriver"); Connection Conn = DriverManager.getConnection ("JDBC: Oracle: Thin: @ 127.0.0.1: 1521: pubdb", "System", "Manager"); Statement Stmt = Conn.createStatement (); ResultSet Rset = Stmt.executeQuery ("Select * from system.suppliers);

While (Rset.next ()) System.out.println (RSET.GETSTRING ("CompanyName"));

Compile, pass, ok

But in JButton1 events, this code is dead, but I have made a few hours of pass, I will change the code as follows:

Class.Forname ("Oracle.jdbc.driver.OracleDriver");

Connection conn = null; string url = "JDBC: Oracle: Thin: @ 127.0.0.1: 1521:" this.jtextfield1.getText (); try {conn = drivermanager.getConnection (URL, "System", "Manager") ;} catch (SQLException ex) {} Statement stmt = null; try {stmt = conn.createStatement ();} catch (SQLException ex1) {} ResultSet rset = null; try {rset = stmt.executeQuery ( "select * from system .suppliers ");} catch (sqlexception ex2) {}

Try {while (rset.next ()) {JOPANE.SHOWMESSAGEDIALOG (this, rset.getstring ("companyName"));}} catch (SQLException EX3) {}

}

Actually passed

Think afterwards, maybe the Java requires the procedure to have the wrong mistake.

But now I feel much, I feel that it is actually good, it is important that it is not worthy :-)

转载请注明原文地址:https://www.9cbs.com/read-32133.html

New Post(0)