나는 데이터베이스에 연결해야하는 나의 첫번째 자바 프로그램을 작성 중이다. 성공적으로 JDBC 드라이버 (버전 4.0)를 만들었으며 성공적으로 ping을 수행합니다. 다음, 나는 코드 아래에 노력하고 그것은 나던 일을. com.sybase. *를 가져와야한다는 것을 알았습니다. 그에 대한. 가져 오기를 확인할 수 없다는 컴파일 오류가 발생합니다. (나는 java에 매우 익숙하다 .. 이것은 나의 첫 번째 프로그램이므로 어떤 도움을 주시면 감사하겠습니다.) 감사. sybase 15.x를 사용하고 있습니다.import com.sybase.jdbc4.jdbc. *; 오류
enter code here
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.sybase.jdbc4.jdbc.*; --> this is where I see error.
public class DBConnTest {
// JDBC driver name and database URL
//static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
//static final String DB_URL = "jdbc:mysql://localhost/EMP";
static final String JDBC_DRIVER = "Sybase15";
static final String DB_URL = "jdbc:sybase:Tds:<IP>:<PORT>/<DB>?CHARSET=iso_1";
// Database credentials
static final String USER = "abc";
static final String PASS = "def";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
//Class.forName("com.sybase.jdbc4.jdbc.SybDriver");
Class.forName("com.sybase.jdbc4.jdbc.SybDriver");
//STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
//STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT ID,AGE,FIRST,AST FROM testtbl";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("ID");
int age = rs.getInt("AGE");
String first = rs.getString("FIRST");
String last = rs.getString("LAST");
//Display values
System.out.print("ID: " + id);
System.out.print(", AGE: " + age);
System.out.print(", FIRST: " + first);
System.out.println(", LAST: " + last);
}
//STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample
안녕하세요. 다행히 첫 번째 문제를 해결할 수있었습니다. 대답에 질문을 넣는 것은 Q/A 형식을 희석하기 때문에 여기서는별로 도움이되지 않습니다. 답변에서 질문을 삭제하고 새로운 질문으로 제출하는 것이 좋습니다. 또는 질문을 편집 할 수 있습니다. –
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc39001.0700/html/prjdbc0700/CIHIGFBE.htm을 보셨습니까? –